Using * when passing argument to alias


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Using * when passing argument to alias
# 1  
Old 06-19-2009
Using * when passing argument to alias

I have some folders with this structure:

/data/me/a123xxx

Where "xxx" is some changing series of letters, and "123" changes so folders might look like:
Code:
/data/me/a123xxx
/data/me/a234ysd
/data/me/a534sds

etc. The numbers are what matter to me (they identify the folder), so I created an alias:

alias gal 'cd /data/me/a\!*'

So if I type gal 123* it'll bring me into the first folder.

But I'd like to have to just type in gal 123 (and not have the * there). How do I put that * into the alias?

---------- Post updated 06-19-09 at 02:22 PM ---------- Previous update was 06-18-09 at 07:44 PM ----------

That might have been too long, here's a shorter version of my question:

How do I make an alias for a command "gal" so that if I type in:

Code:
gal 123

It will be interpreted as:

Code:
cd /data/me/a123*


Last edited by Yogesh Sawant; 06-19-2009 at 10:11 AM.. Reason: added code tags
# 2  
Old 06-19-2009
Create a function - not an alias. Put it in your login script.
# 3  
Old 06-19-2009
Thanks! I've never used functions before in UNIX - what would that look like?

---------- Post updated at 06:19 PM ---------- Previous update was at 04:00 PM ----------

Oh, also, I'm using CSH (putting this all in my .cshrc file).... doing some reading it seems like this doesn't support functions? So.... is there any way for me to do what I'm trying to in my .cshrc?
# 4  
Old 06-22-2009
You don't need to use function for csh - argument can be passed to alias in csh. Function is only for bash.
# 5  
Old 06-22-2009
Thanks... so how do I pass the argument to alias in csh? I think since the argument has a * in it (!*), I can't pass an actual * immediately afterward.
# 6  
Old 06-22-2009
alias ee "more /usr/include/asm-generic/errno-base.h | grep $1" -- alias in .cshrc

to use it,
$ ee 11

But don't know if it'll work for your case, which is more complicated.
# 7  
Old 06-22-2009
Thanks! So... what does that do? I tried that in my shell and got "define EAGAIN", "try again", etc.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Passing a second argument

I am trying to pass a second argument like so: if ] then export ARG2=$2 else message "Second argument not specified: USAGE - $PROGRAM_NAME ARG1 ARG2" checkerror -e 2 -m "Please specify if it is a history or weekly (H or W) extract in the 2nd argument" fi however, it always goes... (4 Replies)
Discussion started by: MIA651
4 Replies

2. Shell Programming and Scripting

Passing an argument using alias to piped command

Hi. I'm trying to do a "simple" thing. grep -rls grepped_exp path | xgs where xgs is an alias to something like: xargs gvim -o -c ":g/grepped_exp" now the problem is that I want to pass the "grepped_exp" to the piped alias. I was able to do something like what I want without the... (4 Replies)
Discussion started by: hagaysp
4 Replies

3. Shell Programming and Scripting

Argument passing

How to pass the alphabet character as a argument in case and in if block? ex: c=$1 if a-z ]] then echo "alphabet" case $1 in a-z) echo "the value is a alphabet" edit by bakunin: please use CODE-tags. We REALLY mean it. (9 Replies)
Discussion started by: Roozo
9 Replies

4. Shell Programming and Scripting

Passing alias to a function

The objective of this function is to validate the file full path. cat /dev/null > crontab_NOTEXISTS.txt function File_Existence # Accepts 1 parameter { file_name="$(echo $1)" echo "${file_name}" && break || echo "$file_name NOT FOUND" >> crontab_NOTEXISTS.txt } while read file_name... (7 Replies)
Discussion started by: aimy
7 Replies

5. Shell Programming and Scripting

awk alias passing a value to a variable

I am trying to turn this into an alias with no luck. I would then like to put the alias into my bashrc file. I know awk is very picky about quotes. I have tried every version of quotes, single quotes, double quotes, and backslashes that I can think of. VAR=$(xrandr | awk '$2=="connected"{s=$1}... (3 Replies)
Discussion started by: cokedude
3 Replies

6. UNIX for Dummies Questions & Answers

Passing variable to Alias in Hp kshell

Hi all, I have a series of directories which i open regularly. I want create an alias so that i can pass the direcotry name to alias and then this commands makes Cd to the path i need. COuld you please help on how to create an alias ex of what i am trying but couldn't succeeded #alias... (1 Reply)
Discussion started by: firestar
1 Replies

7. Shell Programming and Scripting

passing Argument

Hi All, i have script like below.. echo "1) first option" echo "" echo "2) second option" echo "" echo "*) please enter the correct option" read select case $select in 1) echo "first option selected" ;; 2) echo "second option selected" ;; *) echo "please enter the correct... (4 Replies)
Discussion started by: Shahul
4 Replies

8. UNIX for Dummies Questions & Answers

How to create a alias with an argument

If I want to create an alias called "cdr", and this alias need an argument (for example arg1)followed by "cdr", the result should go to the directory like "/home/ting/arg1/report/logs", the command should look like below, alias cdr arg1 "cd /home/ting/\!$1/report/logs" (not working)::( ... (1 Reply)
Discussion started by: ting123
1 Replies

9. UNIX for Dummies Questions & Answers

Passing arguments to an alias

I want to have an alias for the command fold -78 filename | lp How do I set my alias so that the argument passed is filename ?? alias lp='fold -78 | lp' then lp filename wont work cuase this is fold -78 | lp filename (1 Reply)
Discussion started by: pmcg
1 Replies

10. UNIX for Dummies Questions & Answers

1 alias 2 commands 1 argument

Hi, i want make 1 alias with two commands include to do two things at the same time like this: ex: do finger and last at the same time with only one word finla or something. Thanks.- /home/seba > finger dustin Login name: dustin In real life: Dustin Feldman Directory:... (3 Replies)
Discussion started by: seba
3 Replies
Login or Register to Ask a Question