Don't use aliases in your scripts. This is a bad idea for exactly this reason. There are various ways to work around this:
- Define the alias within the script itself
Source the file that contains the alias from the script. Add this line to it:
. /home/your_user/.profile
Use the command itself instead of the alias. For example, if you have alias foo="echo bar", use echo bar in your script instead of foo.
As a general rule, it is a bad idea to set aliases in .profile. That file is only read by login shells, not interactive ones and not when running scripts. To make your aliases easily accessible you should add them to $HOME/.kshrc. The following is from man ksh:
If the shell is invoked by exec(2), and the first character of
argument zero ($0) is -, then the shell is assumed to be a login
shell and commands are read from /etc/profile and then from
either .profile in the current directory or $HOME/.profile, if
either file exists. Next, for interactive shells, commands are
read from the file named by performing parameter expansion,
command substitution, and arithmetic substitution on the value of
the environment variable ENV if the file exists.
In other words, login shells read /etc/profile and .profile while interactive shells (what you get when you open a terminal) read whatever is in the $ENV variable or, if that is not defined, ~/.kshrc. This means that aliases in your .profile will only be read when sshing into the machine or otherwise starting a login shell.
./profile? Why not~/.kshrcwhich would solve your problem?.profilefrom your script, or define the alias in your script or don't use the alias but the actual command. Why in the world can't you use~/.kshrc? That makes no sense, if you can use.profileyou can use.kshrc. Aliases have no business being defined in.profile..profileto define shell-agnostic things, and then source it. see unix.stackexchange.com/questions/88201/…