Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Haveing trouble useing a variable as a command

Status
Not open for further replies.

dman7777777

IS-IT--Management
Jan 13, 2007
52
US
I am a computer operator and I tend a AIX server with Unix usenig the Korn Shell. I have trouble makeing a variable and useing it as a command. For instance, I can make the variable...like this: A=(ls -lt | head) and if I echo it out it shows what is inside the variable. But if I use it as a command....$A...I do not get the desirable results. What am I doing wrong and how can I make a variable that the system will recognize as a command and not just text?
 
It doesn't work because of the embedded pipe symbol..
By the time the shell has come to the stage of expanding variable values, it has forgotten about pipes and the links it needs to set up between the subcommands...

Try this instead:

A='ls -lt|head'
eval $A


HTH,

p5wizard
 
Or you could use an alias, which will handle the pipe properly.
Code:
alias A='ls -lt | head'

-Rod


IBM Certified Advanced Technical Expert pSeries and AIX 5L
CompTIA Linux+
CompTIA Security+

Wish you could view posts with a fixed font? Got Firefox & Greasemonkey? Give yourself the option.
 
If you go for aliases, remember that you use the alias name as a command (without the dollar sign).

# alias A='ls -lt|head'
# A
<output from ls -lt|head command>
...
#

HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top