1

Below function name will set the the current working directory name as tab name using function myfunc but if I pass argument to name then it will set tab name to passed argument.
for e.g.
name mytab [----> this will set the current tab name to mytab]

my bashrc is as follows :

function myfunc {  
echo -n -e "\033]0;${PWD##*/}\007" 
#--- some other thing ---
} 
function name {  
    if [ "$1" ]  
    then  
        unset PROMPT_COMMAND  
        echo -ne "\033]0;${*}\007"  
    else  
        unset PROMPT_COMMAND  
        export PROMPT_COMMAND="history -n; history -w; history -c; history -r; myfunc;$PROMPT_COMMAND"  
    fi  
}  
name  

So if I execute rm $(ls -t | head -1)
I am getting error as /bin/rm: cannot lstat `\033[0m\033[0mReadme.txt\033[0m': No such file or directory

ypp
  • 141
  • 10

1 Answers1

1

Please use the following command

rm $(ls --color=no -t | head -1)

This outputs the result of ls without colors in it, which is what makes your Readme.txt to be shown, instead, as \033[0m\033[0mReadme.txt\033[0m.

Alternatively, you can circumvent the alias of ls by saying \ls --> \ls -t | head -1. More info in Why start a shell command with a backslash?.

Community
  • 1
  • 1
shafeeq
  • 1,499
  • 1
  • 14
  • 30