alias with args how to ...


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers alias with args how to ...
# 1  
Old 12-28-2005
alias with args how to ...

Hello ( sorry newbie question )
I don't understand something im trying to make simple alias that takes 1 arg but it don't gives me the desire result
here is what I have :
stlist | awk '{print "ls -l "$2}'
now I want to translate it to alias that takes instead of the $2 one arg
so I did :
alias stlistdir "stlist | awk '{print "ls -l "\!*}'"
also tried:
alias stlistdir "stlist | awk '{print "ls-l $"\!*}'"

but didn't get the desire results, im getting only the print of the second column when I type : stylistic 2

stlistdir without the ls -l , why ?
# 2  
Old 12-28-2005
It is simple, you only see the command in standard output because you are just printing in awk and you not executing the command.

Could you post the output of stlist command, you want to do ls -lrt to the output of 2nd column of stlist command ?
# 3  
Old 12-28-2005
well this is the thing I don't what it to execute the ls-l command, only to print it
so the output will be when I run the alias stlist 2 for instance:
ls -l file1
ls -l file2
ls -l file3
# 4  
Old 12-28-2005
alias stlistdir "stlist | awk '{print "ls -l "\!*}'"

If you see the above statment, you are using double quotes in two places, one for alias and one for awk.... it obviously mismatch...

try this in ksh

alias stlistdir ="stlist | sed 's/^/ls -l /g'"

The following statement also not working as well..

stlist | awk '{print "ls -l "$2}'

there should be a "," before $2.
# 5  
Old 12-28-2005
I guess I didn't explain my self very well
what I need simply is transform this one liner
stlist | awk '{print "ls -l "$2}'
where stlist is simple program that gives me list of files from repository
and from the output of this stlist command I want to take the second column ( this is the file name )
and add the "ls -l" command, now in the alias I want to make the $2 part as argument
that is sometime the user will get the second column or third depends on the number he typed in the alias
I hope I made my self clear now
thanks
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Edit $args within a command

Hi, I'm using a while loop for a given command "bowtie2" with several parameters. mkdir clean paste <(ls --quote-name ./qc/sg_*_R1_val_1.fq.gz) <(ls --quote-name ./qc/sg_*_R2_val_2.fq.gz) |sed 's/"./-1 ./' | sed 's/gz"\t/gz\t -2 /' | sed 's/"//g' |\ while read args ; do ... (5 Replies)
Discussion started by: sargotrons
5 Replies

2. Shell Programming and Scripting

Problem parsing args

Heya Tooltip: Parsing (getopts) for -u successfully sets mode=umnt, but case umnt is not executed, instead it either executes/show help or regular mount screen. I had copy pasted the structure of a getopts 'structure' from Man Page for getopts (posix Section 1) - The UNIX and Linux Forums... (1 Reply)
Discussion started by: sea
1 Replies

3. Shell Programming and Scripting

Store args passed in array but not the first 2 args

Store args passed in array but not the first 2 args. # bash declare -a arr=("$@") s=$(IFS=, eval 'echo "${arr}"') echo "$s" output: sh array.sh 1 2 3 4 5 6 1,2,3,4,5,6 Desired output: sh array.sh 1 2 3 4 5 6 3,4,5,6 (2 Replies)
Discussion started by: iaav
2 Replies

4. UNIX for Dummies Questions & Answers

Create alias files (not alias commands)

If one: $ find -name 'some expression' -type f > newfile and then subsequently wants to create an alias file from each pathname the find command retrieved and the > placed within 'newfile', how would one do this? Ideally, the newly created alias files would all be in one directory. I am... (3 Replies)
Discussion started by: Alexander4444
3 Replies

5. Shell Programming and Scripting

For Args and Nawk

I am trying to write a simple shell script that will take certain arguments (numerical values) and plug each one into a nawk command. I thought I would need to use for args x y z but i get syntax errors: for args 16 1 3 25 31 41 do nawk -F, '{if($10==$ &&... (8 Replies)
Discussion started by: he204035
8 Replies

6. UNIX for Dummies Questions & Answers

Parameters/Args

Hello, i have a problem. I must write a script, which wants 2 arguments. for example: ./test.sh x.txt y.txtit must be write x.txt in y.txt and when i give 1 or no argument like /.test.sh x.txtmust this give a error message like: SYNTAX <inputfile> <outputfile> my solution is... (5 Replies)
Discussion started by: eightball
5 Replies

7. UNIX for Dummies Questions & Answers

args of 50+ files

Hey.. I've gotten inspired by another thread and used this: #!/usr/bin/bash args 2,5 $(<file.list) It works but I'll like the results separated into different files or back into the 'used'/original files, whatever is easiest. e.g. use fileA | args 2,5 > fileB or fileA and then do this to... (9 Replies)
Discussion started by: lost
9 Replies

8. UNIX for Dummies Questions & Answers

command line args 2

I have this while loop and at the end I am trying to get it to tell me the last argument I entered. And with it like this all I get is the sentence with no value for $1. Now I tried moving done after the sentence and it printed the value of $1 after every number. I don't want that I just want... (2 Replies)
Discussion started by: skooly5
2 Replies

9. Programming

Command line args

My program usage takes the form for example; $ theApp 2 "one or more words" i.e. 3 command line arguments; application name, an integer, some text My code includes the following 4 lines: int anInteger; char words; sscanf(argv, "%d", &anInteger); sscanf(argv, "%s", &message); Based... (2 Replies)
Discussion started by: enuenu
2 Replies

10. Shell Programming and Scripting

Args to Array

Hello all, I have a question. Please help me to populate an array with the arguments passing to a Shell scripts. For example when I call "abc.sh a1 a2 a3" args (a1, a2, ...) recieved in an Array inside the abc.sh arr = a1 arr = a2 and so on... Thanks in advance, (2 Replies)
Discussion started by: Shaz
2 Replies
Login or Register to Ask a Question