Operating System - HP-UX
1833813 Members
2162 Online
110063 Solutions
New Discussion

Why doesn't it work when I issued the command: sh dir

 
May_3
Advisor

Why doesn't it work when I issued the command: sh dir

Hi,

I issued the following commands:
$ alias -x dir='ls -al'
$ sh dir
sh: dir: not found

Thanks!
Best Regards.,
May
May
5 REPLIES 5
Wodisch
Honored Contributor

Re: Why doesn't it work when I issued the command: sh dir

Ni Hao, May!

Aliases are only known within the shell where they were defined - not in sub-shells!

Sorry,
Wodisch
May_3
Advisor

Re: Why doesn't it work when I issued the command: sh dir

Hi, Wodisch

With the option -x, aliases are exported. And an exported alias is defined across the subshell environments.
I got the above words through 'man aliasa', but it doesn't work. I wondered why?

Best Regards.,
May


May
Sukant Naik
Trusted Contributor

Re: Why doesn't it work when I issued the command: sh dir

Hi May,

There are two issues here. What are you doing is creating an alias called dir and tyring to run it as script by doing sh dir.

Obiviously the shell will not find by any filename named dir and it will not execute.(Provided you have no file named dir in the directories defined in the PATH variable)

So you need to do
$ alias -x dir='ls -al'
$ sh
$ dir

The second issue is of the alias getting supported to the child shell. Well, here is an issue. When I checked the man pages for alias. It clearly mentions that when we use -x option alias gets exported to the child shell. But when I tried that it did not work.

Anybody in the forum who can help us.

- Sukant
Who dares he wins
Ralph Grothe
Honored Contributor

Re: Why doesn't it work when I issued the command: sh dir

This puzzles me too.

e.g.

$ alias -x myos="uname -sr"
$ myos
HP-UX B.11.00
$ alias -x|grep myos
myos='uname -sr'
$ sh -c "alias -x|grep myos"
$ echo $?
1

As far as I know the export of aliases or functions are advanced shell features which may only be available in shells such as Bash or sh-posix.
But on the other hand the regular sh on HP-UX claims to be of the latter type.
Hmm...

Thus, I would suggest to create a dot file
$HOME/.shrc
and put therein all your aliases you want to have available in every (not only login) shell.
Then in $HOME/.profile put
ENV=$HOME/.shrc
export ENV
Madness, thy name is system administration
Niraj Kumar Verma
Trusted Contributor

Re: Why doesn't it work when I issued the command: sh dir

hey look like PATH problem

tyr

$ sh ./dir

or use full path name if it
is in your home directory then
try

$sh $HOME/dir

-Niraj
Niraj.Verma@philips.com