Results 1 to 3 of 3
hi all,
I'm wanting to use csh (yes, csh) to build an array of variables similar to the argv command below - fyi the (at) is an 'at' symbol but ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 12-30-2012 #1Just Joined!
- Join Date
- Dec 2012
- Posts
- 6
Defining variables/arrays in csh from stdn/user input
hi all,
I'm wanting to use csh (yes, csh) to build an array of variables similar to the argv command below - fyi the (at) is an 'at' symbol but LF wont let me post 'at's in my first post because it thinks it's a URL:
#! /bin/csh -f
foreach i ($argv[-1])
(at) argnum ++
echo '$argv['$argnum'], argument:' $i
end
which gives me variables for $argv[1], $argv[2], etc
But i want these to come from user input so that it does:
Enter list:
texta
textb
textc
or
Enter list:
texta textb textc
gives a set of variables for later use
${variable1}=texta
${variable2}=textb
${variable3}=textc
How can i replace argv with user input?
Thanks
- 12-30-2012 #2Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,199
Hi.
If you are using tcsh, you probably can use this.
Excerpted from man tcsh, q.v.Code:$< Substitutes a line from the standard input, with no further interpretation thereafter. It can be used to read from the keyboard in a shell script. (+) While csh always quotes $<, as if it were equivalent to `$<:q', tcsh does not. Furthermore, when tcsh is waiting for a line to be typed the user may type an interrupt to interrupt the sequence into which the line is to be substituted, but csh does not allow this.
In a demo script, I used:
In the real csh, I don't know. I think I might have a copy on an old Solaris install, but I have not tried it there.Code:set line = "$<"
Best wishes ... cheers, drl
Standard advice: avoid csh family for scripting, use Bourne shell family. For more on this, see: Csh Programming Considered Harmful
I am posting this only on LF, not on LQ.Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 12-30-2012 #3Just Joined!
- Join Date
- Dec 2012
- Posts
- 6
Defining variables/arrays in csh from stdn/user input- lets try bash
Thanks drl
OK, looks like csh is a non-starter - Trying to do the same thing but with bash but as im unfamiliar with bash i need a little help.
Againi, I need to ask user for a list, take the replies and perform an action on each of them.
Enter list:
texta
textb
textc
or
Enter list:
texta textb textc
and then i need to know how to run a script on each of them.
foreach $input
anotherscript $text[a-c]
continue
Thanks,


Reply With Quote
