|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Dear Everybody:
Aliases with arguments do not work under the shell Bash, but I have used a number of such aliases under tcsh, and the following is a few examples: (1) alias agrep 'grep \!:1 /myhome/.addresses' (1 argument) (2) alias fd 'find /myhome/work/xyz -name \!:1 -print' (1 argument) (3) alias t2ps 'enscript -j -U 2 -C -G --word-wrap -o \!:2 \!:1' (2 arguments) How would you convert the above 3 examples into scripts that can be used under bash? Additionally, can you put the scripts in one single file with each one occupying one line? Thanks for reading and replying! --Roland |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
qquito writes:
> Dear Everybody: > > Aliases with arguments do not work under the shell Bash, but I have > used a number of such aliases under tcsh, and the following is a few > examples: > > (1) alias agrep 'grep \!:1 /myhome/.addresses' (1 > argument) > (2) alias fd 'find /myhome/work/xyz -name \!:1 -print' (1 > argument) > (3) alias t2ps 'enscript -j -U 2 -C -G --word-wrap -o \!:2 \!:1' (2 > arguments) > > How would you convert the above 3 examples into scripts that can be > used under bash? The bash equivalent would be functions, for example: fd() { find ~ -name "$1" -print } then: fd filename The bash equivalent of the other two of your aliases is left for you as a homework excersize. > Additionally, can you put the scripts in one single file with each one > occupying one line? Yes, you can put as many of them as you want, in a file. Bash functions are not limited to one line. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) iD8DBQBGqn7kx9p3GYHlUOIRAqqUAJ9Xce9fPNbmOXRtEBSsxC 05BLPsCQCfZL9M MbXQZt+cAC6XjskXTJ2/2oo= =81Sk -----END PGP SIGNATURE----- |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
In comp.os.linux.misc on Fri, 27 Jul 2007 18:25:28 -0500, Sam
<sam@email-scan.com> wrote: > This is a MIME GnuPG-signed message. ....and therefore inappropriate for Usenet. -- PJR :-) |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
Peter J Ross writes:
> In comp.os.linux.misc on Fri, 27 Jul 2007 18:25:28 -0500, Sam > <sam@email-scan.com> wrote: > >> This is a MIME GnuPG-signed message. > > ...and therefore inappropriate for Usenet. It is very much appropriate. It is true that there are still occasional old fogeys around, who, for some reason, choose to believe that they still live in the 1970s, and the Internet that's not polluted by all those furriners that post messages that contain funny-looking characters, and stubbornly stick to using obsolete mail software that's never been updated to implement modern Internet standards. But, fortunately, that's a small, small minority, and the rest of the world has moved on and joined the 21st century, and adopted modernized and revised standards. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) iD8DBQBGqpLYx9p3GYHlUOIRAuXyAJ9GNW+YXxEUTOzxneGtwb Bl5f94pwCeLl37 b85rkP+HVb9QURBJ6AA+/rU= =Fipj -----END PGP SIGNATURE----- |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On 2007-07-27, qquito wrote:
> Dear Everybody: > > Aliases with arguments do not work under the shell Bash, but I have > used a number of such aliases under tcsh, and the following is a few > examples: > > (1) alias agrep 'grep \!:1 /myhome/.addresses' (1 > argument) > (2) alias fd 'find /myhome/work/xyz -name \!:1 -print' (1 > argument) > (3) alias t2ps 'enscript -j -U 2 -C -G --word-wrap -o \!:2 \!:1' (2 > arguments) > > How would you convert the above 3 examples into scripts that can be > used under bash? Use functions, e.g.: t2ps() { enscript -j -U 2 -C -G --word-wrap -o "$2" "$1" } > Additionally, can you put the scripts in one single file Put them in your ~/.bashrc (or ~/.bash_profile, depending on how your shells are invoked, or whether the former is sourced by the latter), or put them in a separate file and source that from one of the aforementioned files. > with each one occupying one line? Why would you want them each on a single line? Bash is a Bourne-type shell, and all Bourne shells can have compound commands spread over more than one line. You can do it, and with those simple functions, it wouldn't be too bad: agrep() { grep "$1" /myhome/.addresses; } -- Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/> Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) ===== My code in this post, if any, assumes the POSIX locale ===== and is released under the GNU General Public Licence |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
On 2007-07-27, Peter J Ross wrote:
> In comp.os.linux.misc on Fri, 27 Jul 2007 18:25:28 -0500, Sam ><sam@email-scan.com> wrote: > >> This is a MIME GnuPG-signed message. > > ...and therefore inappropriate for Usenet. Nonsense; the message isn't encoded, and a good newsreader can hide the GPG signatures. -- Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/> Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) ===== My code in this post, if any, assumes the POSIX locale ===== and is released under the GNU General Public Licence |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
Thank you, Chris, Sam and other for your replies! I just tried them
and they work! Thanks a lot! --Roland > Use functions, e.g.: > > t2ps() > { > enscript -j -U 2 -C -G --word-wrap -o "$2" "$1" > > } > > Additionally, can you put the scripts in one single file > > Put them in your ~/.bashrc (or ~/.bash_profile, depending on how |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
Hi.
You might also want to consider cshtobash, which you can find via Google. -- Art Werschulz (agw STRUDEL comcast.net) 207 Stoughton Ave Cranford NJ 07016 (908) 272-1146 |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
On 2007-07-29 11:50:23 -0500, Art Werschulz <agw@comcast.net> said:
> You might also want to consider cshtobash, which you can find via > Google. Who me? Why? -- Apply rot13 to my e-mail address before using it. JR |
|
![]() |
| Outils de la discussion | |
|
|