I was following the instructions in https://stackoverflow.com/questions/2135644/how-can-i-define-a-bash-alias-as-a-sequence-of-multiple-commands to create my own bash script. It is as follows:
sudo -u otheruser -i
alias cd1="cd /dir/one/"
alias cd2="cd /dir/two/"
I want these aliases to be available to otheruser
. My goal is to run it as an executable but for testing I am sourcing it (to avoid the problem in https://stackoverflow.com/questions/2197461/how-to-set-an-alias-inside-a-bash-shell-script-so-that-is-it-visible-from-the-ou) like source ./myscript
.
Even with doing that, the sudo works, but none of the following aliases are available (for otheruser
). Do you think the aliases are being applied to the user that invoked this command, and not to the new user? Or is there some rule that commands in a script are ignored after sudo'ing to another user?
/etc/profile
(can depends of your distro)~otheruser/.profile
~otheruser/.profile
because I don't want it to take effect whenever that other user logs in (I don't want to interfere with that user). I only want to enable these commands when I sudo as that user, by running my script. // As for adding this to/etc/profile
if by that you mean my own login script, I don't see how that will help because I want the commands to be available when I'm sudo'd as the other user.cd
command you can use theautojump
command justj one
tocd /dir/one
see here : autojump on github