ypp ypp - 7 months ago 34
Bash Question

bash: if export PROMPT_COMMAND then remove rm $( ls -t | head -1) is not working

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

Answer

Please use the following command

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