How to manage parameter in alias?

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers How to manage parameter in alias?
# 1  
Old 02-10-2018
How to manage parameter in alias?

I make alias in bashrc file and typed it on prompt,

Code:
alias tes='echo "$1"xx"$2"xxx"$3"xxxx'

$ tes a b c
xxxxxxxxx a b c

what's happened to the shell here ?, and also,

Code:
alias tes='echo "$3"xx"$2"xxx"$1"xxxx

$ tes a b c
xxxxxxxxx a b c

anyone sincerely is to help me..
# 2  
Old 02-10-2018
man bash:

Quote:
There is no mechanism for using arguments in the replacement text. If arguments are needed, a shell function should be used (see FUNCTIONS below).
# 3  
Old 02-10-2018
Here is a simple example for what works the way you seem to want - with a function -
On the command line ---- note the continuation characters which you do not enter, bash displays them.
Code:
 $ tes2()
> {
> echo "arg=$1"
> }
$
$ tes2 Hi
arg=Hi
$

The .bashrc that comes with your distro usually has several functions in it it - you can
see what is involved.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Call Script with Parameter (that has another parameter)

Hi. How do I achieve this sh /EDWH-DMT02/script/MISC/exec_sql.sh "@/EDWH-DMT02/script/others/CSM_CKC/Complete_List.sql ${file_name}" Complete_List.txt The /EDWH-DMT02/script/MISC/exec_sql.sh has two parameters and it's working fine with this sh /EDWH-DMT02/script/MISC/exec_sql.sh... (7 Replies)
Discussion started by: aimy
7 Replies

2. UNIX for Dummies Questions & Answers

How to pass a parameter to an alias in ksh?

I want to do something like this: alias cd2="cd /data_saves/$(/opt/bin/util/getcustdb -i $@)" Where /opt/bin/util/getcustdb is an inhouse script to lookup customer db name based on a provided id number Then when I use the alias I can cd2 4567 and have it run "/opt/bin/util/getcustdb -i... (3 Replies)
Discussion started by: JourneyRider
3 Replies

3. Shell Programming and Scripting

Resolving a parameter which is passed as parameter

Hi, I have the following files. ->cat scr.sh export TMP_DIR=/home/user/folder1 export TMP_DIR_2=/home/user/folder2 while read line do cat "$line" done<file_list.dat ------------------------ -> cat file_list.dat $TMP_DIR/file1.txt $TMP_DIR_2/file2.txt --------------------------- -> cat... (6 Replies)
Discussion started by: barath
6 Replies

4. Shell Programming and Scripting

How to get the parameter value from the parameter file in perl?

hi all, i have a parameter file of following format, i want a method which can get the value of specific parameter. parameter file format: <Parameter Name="FileLocationWindows"> <Description> The directory location of the logger file. ... (1 Reply)
Discussion started by: laxmikant.hcl
1 Replies

5. Shell Programming and Scripting

Passing parameter to script, and split the parameter

i am passing input parameter 'one_two' to the script , the script output should display the result as below one_1two one_2two one_3two if then echo " Usage : <$0> <DATABASE> " exit 0 else for DB in 1 2 3 do DBname=`$DATABASE | awk -F "_" '{print $1_${DB}_$2}` done fi (5 Replies)
Discussion started by: only4satish
5 Replies

6. 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

7. Shell Programming and Scripting

Command that takes one parameter and then searches for the passed in parameter

Hi I am looking for a unix command or a small shell script which can takes one parameter and then searches for the passed in the parameter in any or all files under say /home/dev/ Can anyone please help me on this? (3 Replies)
Discussion started by: pankaj80
3 Replies

8. UNIX for Dummies Questions & Answers

Parameter substitution with alias

Hello, in my .bashrc I tried to setup some aliases. alias scp_cmd="scp -P 8888 $1 me@somehost:." is supposed to copy a local file to somehost via scp. However it seems that the command line substitution does not work here. However this works: alias lst="ls -l $1" The above scp command can... (1 Reply)
Discussion started by: strobotta
1 Replies

9. Shell Programming and Scripting

how do I make dynamic parameter names? Or get the value of a parameter evaluated twi

Say I write something like the following: var1=1 var2=2 for int in 1 2 do echo "\$var$int" done I want the output to be: 1 2 Instead I get something like: $var1 $var2 (2 Replies)
Discussion started by: Awanka
2 Replies

10. UNIX for Dummies Questions & Answers

Manage Mail

I have recently taken over a UNIX system from another programmer and am just beginning to learn UNIX. When I enter the MAIL command, the data scrolls off the screen for five minutes. Some of it is several years old. Can I tell the MAIL command to give me the last few items or the last few... (1 Reply)
Discussion started by: SUSANR9999
1 Replies
Login or Register to Ask a Question