You would be better served by a shell function:
doit () {
local dir
case $PWD/ in
/home/alpha/*) dir=alpha ;;
/home/beta/*) dir=beta ;;
/home/gamma/*) dir=gamma ;;
*) echo 'Not standing in the correct directory' >&2
return 1
esac
python "/home/$dir/src/doit.py" --clean "$@"
}
This would set the variable dir
to the string alpha
, beta
or gamma
depending on the current working directory, or complain that you're in the wrong directory tree if the current directory is elsewhere.
It then runs the Python script, utilizing the $dir
value, with the --clean
option and adds whatever other arguments that you've passed to the function.
You would add this shell function's definition to wherever you ordinarily add aliases.
Bash does allow aliases to contain aliases but it has built-in protections against infinite loops. In your case, when you type lsc
, bash first expands the alias to:
ls -Flatr --color=always
Since ls
is also an alias, bash expands it to:
lsc -Flatr --color=always
lsc
is an alias but, quite sensibly, bash refuses to expand it a second time. If there was a program named lsc
, bash would run it. But, there is not and that is why you get command not found
.
Addendum
It is different when lscR
runs. lscR
expands to:
ls -FlatrR --color=always
Since ls
is an alias, this expands to:
lsc -FlatrR --color=always
Since lsc
is an alias, this expands to:
ls -Flatr --color=always -FlatrR --color=always
Since ls
has already been expanded once, bash refuses to expand it a second time. Since a real command called ls
exists, it is run.
History
As noted by Schily in the comments, bash borrowed the concept of not expanding an alias a second time from ksh.
Aside
Aliases are useful but not very powerful. If you are tempted to do something complex with an alias, such as argument substitution, don't; use a shell function instead.
Best Answer
Create a function:
Now invoking the command
reboot
would invoke the functionreboot
which would ignore all parameters passed to it.That is:
and
would execute the command
reboot
(without any argument).