Operating System - Tru64 Unix
1748244 Members
3807 Online
108760 Solutions
New Discussion юеВ

Setting alias in a script to be use on cmd line in ksh.

 
SOLVED
Go to solution
Jean-Pierre Denis
Valued Contributor

Setting alias in a script to be use on cmd line in ksh.

Hi,

I trying to set an alias that would be accessible from the command line in a shell script that would read the user input.

We need to manually monitor a backup that have the date in the log file. So instead of typing the long alias everyday I wrote a script that would set the alias.
The script would be run, the date entered and than the log file would be view with more.
We set bf to monitor files sytem backup and bo to monitor os backup.
Unfortunately, once the script is executed the alias do not work on the command line.

I receive the message: ksh: bf not found

I thought that using alias -x in the script would do the trick but unfortunately it does not work.

Any ideas or pointer would be great !


Here is the script:

#!/bin/ksh
clear
echo "Please enter the backupfs and backupos date (ddmmyy):"
read backupdate
# Create the alias for backupfs and backupos
alias -x bf='more /usr/it/custom/apps/backup/log/$backupdate.fslog'
alias -x bs='more /usr/it/custom/apps/backup/log/$backupdate.oslog'
echo "The alias were create"
echo "You can now issue bf and bo to monitor the backup"


Thanks,
JP
Open your Mind and use Open Source software...
2 REPLIES 2
Michael Schulte zur Sur
Honored Contributor
Solution

Re: Setting alias in a script to be use on cmd line in ksh.

if you call the script, it starts a new shell and after the script is finished, the alias is gone. Try . ./script

Michael
Jean-Pierre Denis
Valued Contributor

Re: Setting alias in a script to be use on cmd line in ksh.

Hi,

Thanks Micheal,
it's working if I call the script like this:

#. script

Thanks,
JP
Open your Mind and use Open Source software...