LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-07-2009, 04:23 AM   #1
DoME69
Member
 
Registered: Jan 2008
Posts: 189

Rep: Reputation: 16
How can i add few arguments at "alias"?


Hi

i want to add few arguments at alias

Example:

alias GGG 'bla bla bla ARG1 ARG2 bla bla bla bla ARG3 ARG4 bla bla'

> GGG ARG1 ARG2 ARG3 ARG4

Thanks
 
Old 01-07-2009, 05:08 AM   #2
indeliblestamp
Member
 
Registered: Feb 2006
Distribution: Fedora
Posts: 341
Blog Entries: 3

Rep: Reputation: 40
You could define a function in your .bashrc instead of defining an alias. Then use $1, $2 etc to specify the args individually. e.g. this works for me:
Code:
arun ~ $ function temp { echo "this is arg1: $1, and arg2: $2" ; echo "this is arg3: $3" ; }
arun ~ $ temp asd qew zxc
this is arg1: asd, and arg2: qew
this is arg3: zxc
arun ~ $
 
Old 01-07-2009, 05:12 AM   #3
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 66
You need to use a function for this:
Code:
[yves@localhost ~]$ function test(){ echo "you said: " "$@"; }
[yves@localhost ~]$ test hello "you
and
you"
you said:  hello you
and
you
Yves.
 
Old 01-07-2009, 05:14 AM   #4
DoME69
Member
 
Registered: Jan 2008
Posts: 189

Original Poster
Rep: Reputation: 16
I`m using cshell.

could you please show it at cshell?

Thanks.
 
Old 01-07-2009, 05:41 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
The C-shells /bin/csh and /bin/tcsh does not support functions. However you can use arguments in the alias body. For example, suppose you define the following
Code:
alias silly 'echo \!:1 AND \!:2* AND \!*'
and then issue the command:
Code:
$ silly hello world hi people
hello AND world hi people AND hello world hi people
As you can see the arguments are designated as \!:1 (the first argument), \!:2* (from the second to the last) and \!* (all the argument list). Note that if you don't pass a required argument, the shell complains about it. For example, using the alias above without arguments, will result in
Code:
$ silly
Bad ! arg selector.
Anyway, here is an interesting link!


Edit: if you have to stick with a C-shell, here is some resources on csh and tcsh programming: http://www.kitebird.com/csh-tcsh-book/

Last edited by colucix; 01-07-2009 at 05:49 AM.
 
Old 01-07-2009, 06:11 AM   #6
DoME69
Member
 
Registered: Jan 2008
Posts: 189

Original Poster
Rep: Reputation: 16
Thanks colucix

 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cant "source" bash script with arguments (PATH updating) monkey_king Linux - General 5 12-30-2008 04:34 AM
IPW2200 Make error macro "create_workqueue" passed 2 arguments, but takes just 1 jplev22 Linux - Wireless Networking 2 09-16-2005 11:34 AM
add "Artist" and "Album Title" to mp3 files powah Linux - Software 2 04-05-2005 03:04 AM
bash equivalence of tcsh "alias em "emacs \!:1 &""? rgiggs Slackware 3 07-29-2004 02:07 AM
how to change "kernel arguments" in grub boot loader permanently stupid_guy Linux - Newbie 7 06-09-2003 10:32 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration