It is currently Tue, 17 May 2022 17:48:50 GMT



 
Author Message
 Just a question about a shell script
I have a script that has aliases in it.  One of my co-workers didn't like
how I was doing it.

Basically imagine a large multi-line file that looks like this:

alias comp1="/usr/openwin/bin/xterm -bg black -fg green -fn fixed +cn -T
comp1 -n comp1 -j -sb -si -sk -sl 2000 -wf -geometry 80x40 -e
/usr/bin/rlogin -l root comp1.dom.com &"

I don't mind having the large file, it's easy to yank/paste/replace what I
need.  But it's a mental exercise, and I said sure, what the hell.

So I've gotten to this point where the file I keep the aliases looks
something like this (shortened for testing purposes):

XTERM='/usr/openwin/bin/xterm -T $1 -e rlogin -l root $2'

alias test='$XTERM comp1 comp1.dom.com`

The two problems I'm having (and I didn't realize until just recently that
there was a second) was that 1. I can't get rlogin to exec using the -e
option.  2. I'm unfamiliar with how in a script to use a command line arg
such that $1 and $2 take what I'm giving them, e.g. comp1 and comp1.dom.com

I've looked at xargs (man xargs) but I'm not sure if that's what I want/need
to use or not.

Thanks,

    -J



 Mon, 13 Oct 2003 02:01:06 GMT   
 Just a question about a shell script
In article <9c73e5$...@spamz.news.aol.com>,
Jason C. Hill <jhi...@gmu.edu> wrote:

I'm not sure what's causing problem 1.  But regarding problem 2, aliases
can't process arguments.  Use functions instead.  Aliases are only usable
when you want to do a simple, direct substitution.

Actually, my preference is not to use aliases or functions at all, but just
make a separate shell script for each thing you do.  Put them in a
directory like $HOME/bin and add this to your PATH.  I have lots of 1-5
line scripts like this.

--
Barry Margolin, bar...@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.



 Mon, 13 Oct 2003 02:19:08 GMT   
 Just a question about a shell script
Yeah, another friend of mine that I asked about this mentioned the exact
same thing...However, the problem is, we're talking at least a hundred hosts
(maybe a tad less in the 70s~80s), with the possibility as responsibilities
change of this being hundreds of hosts...So, maintaining all those little
files...ugg

Thanks for answering #2, that makes sense, I appreciate it.

    -Jason



 Mon, 13 Oct 2003 02:38:32 GMT   
 Just a question about a shell script
In article <vyEF6.49$Lt5.778@burlma1-snr2>,

This is good advice,  but you can create ksh aliases that will take
positional parameters,  although this feature is largely of academic
interest. Observe the following:

      alias newterm="ksh -c 'exec xterm -bg "'${1:-white}'"'"

this relies upon the fact that in a "ksh -c list" construct,  any
subsequent parms will be passed to the list.  The same method can be used
in a "find path -exec" statement:

      $ find / -name example.c -exec ksh -c 'cd ${1%/*};echo "$PWD:";ls' {} \;
      /home/dam/example:
      RCS        example    example.c  example.h  example.o  makefile

--
Dan Mercer
damer...@mmm.com

Opinions expressed herein are my own and may not represent those of my employer.



 Mon, 13 Oct 2003 02:53:18 GMT   
 Just a question about a shell script

bash too has the -c option, and I've tried that as well, however, I end up
right back at the same problem of the rlogin coming back as a bad command
line option, which is I believe related to the part that I can't see to pass
rlogin the arguments it needs.

for example, I tried:

XTERM="/usr/local/bin/bash -c '/usr/openwin/bin/xterm -T $1 -e
/usr/bin/rlogin -l root $2'"

alias test="$XTERM comp1 comp2"  <-- this could be leading back to the same
old alias = no arg problem again.

I'm interested in trying out the function ... and I've opened the bash book
to the function part, and I can see what they're doing via their examples,
but I'm having a hard wrapping up what they're doing ... transposing it ...
and unwrapping it to my problem...it could just be that it's b/c I'm at
work, and have other things on my mind...or it could just be that it's one
of those neuron not making a connection with another neuron thing, and thus
causing a spark.

Regardless, I'm spending WAY to much time on a mental exercise than I should
be ;-)

    -J



 Mon, 13 Oct 2003 03:25:37 GMT   
 Just a question about a shell script

Not sure about the real problem, but I'd avoid calling anything
'test'.



 Mon, 13 Oct 2003 17:56:23 GMT   
 Just a question about a shell script
"Jason C. Hill" <jhi...@gmu.edu> wrote in message
news:9c73e5$7te@spamz.news.aol.com...

sha@bofh:/tmp$ ASDF="asdf"
sha@bofh:/tmp$ echo '$ASDF'
$ASDF
sha@bofh:/tmp$ echo "$ASDF"
asdf
sha@bofh:/tmp$

Get it? Stuff within single qutoes is protected from shell expansion. Stuff
within double quotes ins't.

====================================================================
S?ren Hansen
UNIX Systems Administrator
Mindpass.com, Vardevej 1, DK-9220 Aalborg
Reception: +45 9635 2000, GSM: +45 2077 3385, fax: +45 9635 2099
s...@mindpass.com



 Mon, 13 Oct 2003 22:17:19 GMT   
 Just a question about a shell script
In article <9c9ah5$ba...@news.inet.tele.dk>,

In this case, the quoting is correct.  If double quotes were used, the
variables would be expanded when the alias is defined, but he wants them to
be expanded when the alias is *used*.

It's a separate problem that $1 and $2 don't work in aliases, which I
pointed out in my earlier response.

--
Barry Margolin, bar...@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.



 Tue, 14 Oct 2003 03:20:01 GMT   
 
   [ 8 post ] 

Similar Threads

1. shell script within shell script (general question)

2. a question about executing a shell script (c-shell)

3. A Solaris 8 (Bourne Shell) Scripting question, regarding a log rotation script

4. Korn Shell Scripting Question, Restarting a script

5. Shell script question, (2 questions)

6. Convert Bash shell script to Korn shell script

7. Shell Script Help (C-Shell Script)

8. Shell script invoking other shell scripts

9. PartitionMagic justs hangs


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software