Operating System - HP-UX
1753726 Members
4671 Online
108799 Solutions
New Discussion юеВ

Passing parameters to middle of alias script

 
eric stewart
Frequent Advisor

Passing parameters to middle of alias script

This is for the lazy person.
They want to set up an alias called Z to print a file in the background. I think it should look like
export alias Z='cat $1 &'
or
export alias Z='cat $* &'

All test show
ksh: 1: parameter not set
ksh: /etc/motd: cannot execute

TIA. Also if I did not assign some points to a question yesterday is it to late?
Good help is easy to find within forums
8 REPLIES 8
Berlene Herren
Honored Contributor

Re: Passing parameters to middle of alias script

It's never too late!

Berlene
http://www.mindspring.com/~bkherren/dobes/index.htm
John Palmer
Honored Contributor

Re: Passing parameters to middle of alias script

export alias Z='cat $1 &'
would only work within a script where $1 was declared. It won't work at command prompt level.

Alias works by substituting the text of the alias for the aliased command itself so typing Z results in the shell executing
cat $1 &

You get ksh: 1: parameter not set because $1 is not set and you have set -u on to warn about undeclared variables. Try man sh-posix.

How does the user intend supplying the name of the file that they want to cat? Would it be Z ?

If so, and they are really that lazy, just write a simple shell script such as:-
#!/usr/bin/sh
cat $1 &

Hope this helps,
John
Andreas Voss
Honored Contributor

Re: Passing parameters to middle of alias script

Hi,

Your alias didn't work because the shell appends parameter after the whole alias.
Ie.: Z /etc/motd would give:
cat & /etc/motd
That's why you get the errors.
Think you have to create a script for it:
Put a file Z into a directory where PATH looks in with the contents:
lp $* &
And make chmod +x to it.
Regards

Andrew
eric stewart
Frequent Advisor

Re: Passing parameters to middle of alias script

They are that lazy.
They did not want to have an extra script.
They did not want to have to add the & at the end of the command line but make it part of the alias. Is that lazy:).
They were going to enter
Z /etc/motd
Remember this is just an example. The real alias is longer in command characters and length of execution.
Good help is easy to find within forums
Brian M. Fisher
Honored Contributor

Re: Passing parameters to middle of alias script

I agree with the other responses. A simple script located in a directory that is already in the users search patch would make adding and changing the script easier than an alias.

Brian
<*(((>< er
Perception IS Reality
eric stewart
Frequent Advisor

Re: Passing parameters to middle of alias script

Thanks for the replies.
I thought that's what the forum would reply.
I think this forum is great.
I can try different things and waste a lot of time but when the 'experts' tell me where to go to find something or that my thinking is correct on a solution it make me secure in my thought process.
I would also like to thank HP for supporting this. I am sure it cuts down on support calls.
Good help is easy to find within forums
curt larson
Frequent Advisor

Re: Passing parameters to middle of alias script

Why don't you create a shell function.
put it into which ever dot file has your alias'

function Z {
cat $1 &
return
}
nobody else has this problem
eric stewart
Frequent Advisor

Re: Passing parameters to middle of alias script

Curt, your answer was right on but a little late. My cubical mate had done exactly what you suggested and showed me after he realized what the user really wanted.
YOu do get honorable mention.
Good help is easy to find within forums