I have the following in my ~/.bashrc to hide the listing of test from the output of ls:alias ls='ls -I test'But I want it to only hide test if my current working directory is the root (/) folder, not if I am in some other folder.How may I achieve this?
Only if in / : alias ls='ls -I test'?
bash;ls;alias
Something like this i thought it would work:alias ls='[[ $PWD = / ]] && ls -I test ||ls'$PWD is the current working directory&& has the action to perform if pwd is / (condition check =true)|| has the action to perform if pwd is not /  (condition check=false)  But after carefull testing above solution IS NOT WORKING correctly.On the other hand this will work ok as alternative to functions:alias ls='{ [[ $PWD == / ]] && a=-I tmp2 ||a=; };ls $a 'Or even better, similar to other answers but without the need of function:alias lstest='{ [[ $PWD == / ]] && set -- -I tmp2 || set --; }; ls $@'Possible extra flags and/or full paths given in command line when invoking this alias are preserved and sent to ls.