I am missing something basic with bash scripting.
I am trying to get away from hard coded server names in a script using case for valid name check This works but is not good because as soon as you add a new server to the NFS mountpoint list the script this is from has to be changed. case $target_system in abinodji | calhoun | itasca | nokomis | pepin | phalen | vadnais | bemidji | millpond | mudlake | terrapin | hadley | hyland ) parm_1="valid";; esac So I tried several variants of this: space=" " delim=" | " raw_list=`ls /clamscan/servers` #read list of mountpoints cooked_list=$(echo $raw_list | sed -e "s:$space:$delim:g") #replace space with case-happy delimiters echo "Raw list = "$raw_list echo "cooked list = "$cooked_list case $target_system in $cooked_list ) parm_1="valid" ;; esac But even though the display of 'cooked_list' seems to be what I want it to be, this never returns a match. Anyone see where I missed the turnip truck on this? -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390
Re: I am missing something basic with bash scripting.
>>> On Thu, Sep 6, 2007 at 4:53 PM, in message <[EMAIL PROTECTED]>, James Melin <[EMAIL PROTECTED]> wrote: -snip- > raw_list=`ls /clamscan/servers` #read list of mountpoints -snip- > But even though the display of 'cooked_list' seems to be what I want it to > be, this never returns a match. > Anyone see where I missed the turnip truck on this? I'm guessing that if you subsitute /bin/ls instead of just "ls" (and change the whole thing to $(/bin/ls /clamscan/servers) to satisfy Adam) that thing will work better. I think you're likely getting trailing "/"es on the end of the names, but that's not how you're passing in target_system. Mark Post -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390
Re: I am missing something basic with bash scripting.
I'll try that however my echo's are not revealing that to be the case. Stay tuned. Mark Post <[EMAIL PROTECTED]> Sent by: Linux on 390 Port To LINUX-390@VM.MARIST.EDU cc 09/06/2007 04:07 PM Subject Re: I am missing something basic with bash scripting. Please respond to Linux on 390 Port >>> On Thu, Sep 6, 2007 at 4:53 PM, in message <[EMAIL PROTECTED]>, James Melin <[EMAIL PROTECTED]> wrote: -snip- > raw_list=`ls /clamscan/servers` #read list of mountpoints -snip- > But even though the display of 'cooked_list' seems to be what I want it to > be, this never returns a match. > Anyone see where I missed the turnip truck on this? I'm guessing that if you subsitute /bin/ls instead of just "ls" (and change the whole thing to $(/bin/ls /clamscan/servers) to satisfy Adam) that thing will work better. I think you're likely getting trailing "/"es on the end of the names, but that's not how you're passing in target_system. Mark Post -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390 -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390
Re: I am missing something basic with bash scripting.
The problem is that bash takes cooked_list as a single token in the case statement. It matches the entire list of systems, and not each member of the list. I don't know of any way around this. You will probably need to do another for loop on raw_list and check for a match in the loop. -Original Message- From: Linux on 390 Port [mailto:[EMAIL PROTECTED] Behalf Of James Melin Sent: Thursday, September 06, 2007 1:53 PM To: LINUX-390@VM.MARIST.EDU Subject: I am missing something basic with bash scripting. I am trying to get away from hard coded server names in a script using case for valid name check This works but is not good because as soon as you add a new server to the NFS mountpoint list the script this is from has to be changed. case $target_system in abinodji | calhoun | itasca | nokomis | pepin | phalen | vadnais | bemidji | millpond | mudlake | terrapin | hadley | hyland ) parm_1="valid";; esac So I tried several variants of this: space=" " delim=" | " raw_list=`ls /clamscan/servers` #read list of mountpoints cooked_list=$(echo $raw_list | sed -e "s:$space:$delim:g") #replace space with case-happy delimiters echo "Raw list = "$raw_list echo "cooked list = "$cooked_list case $target_system in $cooked_list ) parm_1="valid" ;; esac But even though the display of 'cooked_list' seems to be what I want it to be, this never returns a match. Anyone see where I missed the turnip truck on this? -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390 -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390
Re: I am missing something basic with bash scripting.
On Thursday 06 September 2007 16:53, James Melin wrote: >I am trying to get away from hard coded server names in a script using case > for valid name check > >This works but is not good because as soon as you add a new server to the > NFS mountpoint list the script this is from has to be changed. > >case $target_system in > abinodji | calhoun | itasca | nokomis | pepin | phalen | vadnais | bemidji > | millpond | mudlake | terrapin | hadley | hyland ) parm_1="valid";; esac > > >So I tried several variants of this: > >space=" " >delim=" | " >raw_list=`ls /clamscan/servers` #read list of mountpoints >cooked_list=$(echo $raw_list | sed -e "s:$space:$delim:g") #replace space > with case-happy delimiters echo "Raw list = "$raw_list >echo "cooked list = "$cooked_list >case $target_system in > $cooked_list ) parm_1="valid" ;; >esac > >But even though the display of 'cooked_list' seems to be what I want it to > be, this never returns a match. > >Anyone see where I missed the turnip truck on this? Yup: your $cooked_list inside that case statement represents a single pattern whose value is a set of words separated by vertical bar characters and whitespace. What you want it to be is a list of separate patterns. You see, the shell breaks that case statement apart into words before doing parameter substitutions, so it expects to parse the vertical bars separating multiple patterns in a case before it expands that variable. You could use eval to handle this, but there is a better way. Don't use case at all. Define a simple InList() function that tells you if a given value is in a list of values. I use this in scripts all the time: # Function to determine if a value is in a list of values. The arguments # are the value to check, and one or more other values which are the list # to look for that first value in. Returns zero if the first argument is # repeated as any subsequent argument, or one if it is not. InList() { local value="$1" shift while [ $# -ne 0 ] do if [ "$1" = "$value" ]; then return 0; fi shift done return 1 } Note that this function uses only shell built-in commands, so it is pretty efficient. To get your list of known servers, do this: Servers="$('ls' /clamscan/servers)" Note that I'm using $(...) instead of backticks. Backticks are evil! I'm also quoting the ls command to avoid any alias expansions, or you could explicitly invoke /bin/ls. Now you can do your check like this: if InList "$target_system" $Servers thenparm_1="valid" fi I encourage you to use functions extensively in your shell scripts. They make the code much easier to read! You can use function arguments, the standard input, and global variables as inputs to functions, and the return code, standard output and global variables as outputs. I don't recommend using global variables other than as static inputs (eg. configuration values). Here's a way to write InList() using standard input and output instead, which shows the common idioms for doing that: # Function to determine if a value is in a list of values. The only argument # is the value to check. The standard input contains a list of other values # to look for that first value in, one value per line. Writes "valid" to the # standard output if the argument is in the list on the standard input, # otherwise there is no output. There is no return value. InList() { local item while read item do if [ "$item" = "$1" ]; then echo "valid"; return; fi done } It would be used like this: parm_1="$('ls' -1 /clamscan/servers | InList "$target_system")" Note: that's a "digit one" option to ls, not an "ell", to force the output to have one server name per line. This example does the same as the first version, but is less efficient because it uses I/O mechanisms. If you know your server list is not going to be very long (< 10K bytes), then use the first method. If you want to handle lists of arbitrary size, use the I/O method. - MacK. - Edmund R. MacKenty Software Architect Rocket Software, Inc. Newton, MA USA -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390
Re: I am missing something basic with bash scripting.
Ahh. I had seen an example in the o'reilly text 'learning the bash shell' that made it appear variable substitution in case was valid, but considering they were using $PWD as the variable, indeed it would be the entire string. I'll try the loop in the morning. It would be nice if case DID work that way though. "Fargusson.Alan" <[EMAIL PROTECTED]> Sent by: Linux on 390 Port To LINUX-390@VM.MARIST.EDU cc 09/06/2007 04:23 PM Subject Re: I am missing something basic with bash scripting. Please respond to Linux on 390 Port The problem is that bash takes cooked_list as a single token in the case statement. It matches the entire list of systems, and not each member of the list. I don't know of any way around this. You will probably need to do another for loop on raw_list and check for a match in the loop. -Original Message- From: Linux on 390 Port [mailto:[EMAIL PROTECTED] Behalf Of James Melin Sent: Thursday, September 06, 2007 1:53 PM To: LINUX-390@VM.MARIST.EDU Subject: I am missing something basic with bash scripting. I am trying to get away from hard coded server names in a script using case for valid name check This works but is not good because as soon as you add a new server to the NFS mountpoint list the script this is from has to be changed. case $target_system in abinodji | calhoun | itasca | nokomis | pepin | phalen | vadnais | bemidji | millpond | mudlake | terrapin | hadley | hyland ) parm_1="valid";; esac So I tried several variants of this: space=" " delim=" | " raw_list=`ls /clamscan/servers` #read list of mountpoints cooked_list=$(echo $raw_list | sed -e "s:$space:$delim:g") #replace space with case-happy delimiters echo "Raw list = "$raw_list echo "cooked list = "$cooked_list case $target_system in $cooked_list ) parm_1="valid" ;; esac But even though the display of 'cooked_list' seems to be what I want it to be, this never returns a match. Anyone see where I missed the turnip truck on this? -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390 -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390 -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390
Re: I am missing something basic with bash scripting.
This: (put it off into a little test script of its own) parm_1="invalid" target_system="hadley" space=" " delim=" | " raw_list=$(/bin/ls /clamscan/servers) cooked_list=$(echo $raw_list | sed -e "s:$space:$delim:g") echo "Raw list = "$raw_list echo "cooked list = "$cooked_list case $target_system in $cooked_list ) parm_1="valid" ;; esac echo "Parm_1 =" $parm_1 produces: Raw list = abinodji aitken albert bemidji calhoun hadley hyland itasca millpond mudlake nokomis pepin pequot phalen terrapin vadnais cooked list = abinodji | aitken | albert | bemidji | calhoun | hadley | hyland | itasca | millpond | mudlake | nokomis | pepin | pequot | phalen | terrapin | vadnais Parm_1 = invalid Mark Post <[EMAIL PROTECTED]> Sent by: Linux on 390 Port To LINUX-390@VM.MARIST.EDU cc 09/06/2007 04:07 PM Subject Re: I am missing something basic with bash scripting. Please respond to Linux on 390 Port >>> On Thu, Sep 6, 2007 at 4:53 PM, in message <[EMAIL PROTECTED]>, James Melin <[EMAIL PROTECTED]> wrote: -snip- > raw_list=`ls /clamscan/servers` #read list of mountpoints -snip- > But even though the display of 'cooked_list' seems to be what I want it to > be, this never returns a match. > Anyone see where I missed the turnip truck on this? I'm guessing that if you subsitute /bin/ls instead of just "ls" (and change the whole thing to $(/bin/ls /clamscan/servers) to satisfy Adam) that thing will work better. I think you're likely getting trailing "/"es on the end of the names, but that's not how you're passing in target_system. Mark Post -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390 -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390
Re: I am missing something basic with bash scripting.
On 9/6/2007 4:31 PM, Edmund R. MacKenty wrote: Note that I'm using $(...) instead of backticks. Backticks are evil! The InList() function is slick; I like it! But I'm curious: why are backticks evil? (I didn't know about the "$(command)" trick; I've been using backticks for a long time. I learn something new every day!) Eric -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390
Re: I am missing something basic with bash scripting.
> parm_1="invalid" > target_system="hadley" > space=" " > delim=" | " > raw_list=$(/bin/ls /clamscan/servers) > cooked_list=$(echo $raw_list | sed -e "s:$space:$delim:g") > echo "Raw list = "$raw_list echo "cooked list = "$cooked_list > case $target_system in > $cooked_list ) parm_1="valid" ;; > esac My $0.028 -- parm_1="invalid" for system in `/bin/ls /clamscan/servers` ; do [ "x$system" = "x$target_system" ] && parm_1="valid" done ok r. -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390
Re: I am missing something basic with bash scripting.
>>> On Thu, Sep 6, 2007 at 5:10 PM, in message <[EMAIL PROTECTED]>, James Melin <[EMAIL PROTECTED]> wrote: > I'll try that however my echo's are not revealing that to be the case. > Stay tuned. If that doesn't help, then put a "set -x" right after the #!/bin/sh line, and send the output, along with the command invocation. Mark Post -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390
Re: I am missing something basic with bash scripting.
This is probably the closest to what you're trying to do without getting too fancy: declare -a cooked_list=$(ls /clamscan/servers/) for server in [EMAIL PROTECTED]; do if [ "$server" == "$target_system" ]; then parm_1="valid" break else parm_1="invalid" fi done -Original Message- From: Linux on 390 Port [mailto:[EMAIL PROTECTED] On Behalf Of James Melin Sent: Thursday, September 06, 2007 5:10 PM To: LINUX-390@VM.MARIST.EDU Subject: Re: I am missing something basic with bash scripting. I'll try that however my echo's are not revealing that to be the case. Stay tuned. Mark Post <[EMAIL PROTECTED]> Sent by: Linux on 390 Port To LINUX-390@VM.MARIST.EDU cc 09/06/2007 04:07 PM Subject Re: I am missing something basic with bash scripting. Please respond to Linux on 390 Port >>> On Thu, Sep 6, 2007 at 4:53 PM, in message <[EMAIL PROTECTED] n.us>, James Melin <[EMAIL PROTECTED]> wrote: -snip- > raw_list=`ls /clamscan/servers` #read list of mountpoints -snip- > But even though the display of 'cooked_list' seems to be what I want it to > be, this never returns a match. > Anyone see where I missed the turnip truck on this? I'm guessing that if you subsitute /bin/ls instead of just "ls" (and change the whole thing to $(/bin/ls /clamscan/servers) to satisfy Adam) that thing will work better. I think you're likely getting trailing "/"es on the end of the names, but that's not how you're passing in target_system. Mark Post -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390 -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390 -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390
Re: I am missing something basic with bash scripting.
Because it is very hard to nest them. -Original Message- From: Linux on 390 Port [mailto:[EMAIL PROTECTED] Behalf Of Eric Chevalier Sent: Thursday, September 06, 2007 2:56 PM To: LINUX-390@VM.MARIST.EDU Subject: Re: I am missing something basic with bash scripting. On 9/6/2007 4:31 PM, Edmund R. MacKenty wrote: > Note that I'm using $(...) instead of backticks. Backticks are evil! The InList() function is slick; I like it! But I'm curious: why are backticks evil? (I didn't know about the "$(command)" trick; I've been using backticks for a long time. I learn something new every day!) Eric -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390 -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390
Re: I am missing something basic with bash scripting.
On Thursday 06 September 2007 17:56, Eric Chevalier wrote: >On 9/6/2007 4:31 PM, Edmund R. MacKenty wrote: >> Note that I'm using $(...) instead of backticks. Backticks are evil! > >The InList() function is slick; I like it! > >But I'm curious: why are backticks evil? (I didn't know about the >"$(command)" trick; I've been using backticks for a long time. I learn >something new every day!) I used to use backticks all the time too, but I never much liked them because they are so easy to confuse with single-quotes, and on some proportional fonts they are very hard to see, even. When I found that even the Bourne shells on UNIX systems all support $(...) for command substitutions, I switched for good. BTW: the best solution posted so far is Lary Ploetz's: [[ -f /clamscan/servers/$target_system ]] && parm_1="valid" which avoids the entire "is this value in this list" problem completely. Very nice! I would, however, use -e instead of -f, because the system name is probably a directory, not a plain file. - MacK. - Edmund R. MacKenty Software Architect Rocket Software, Inc. Newton, MA USA -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390
Re: I am missing something basic with bash scripting.
On 9/6/2007 5:04 PM, Fargusson.Alan wrote: Because it is very hard to nest them. Ah hah! I'd never thought about that. Thanks! Eric -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390
Re: I am missing something basic with bash scripting.
> I would, however, use -e instead of -f, because the system > name is probably a directory, not a plain file. indeed, then why not use -d ? ok r. -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390
Re: I am missing something basic with bash scripting.
On Sep 6, 2007, at 2:56 PM, Eric Chevalier wrote: On 9/6/2007 4:31 PM, Edmund R. MacKenty wrote: Note that I'm using $(...) instead of backticks. Backticks are evil! The InList() function is slick; I like it! But I'm curious: why are backticks evil? (I didn't know about the "$(command)" trick; I've been using backticks for a long time. I learn something new every day!) Backticks don't nest (without extensive and tricky escaping). $() does. Adam -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390
Re: I am missing something basic with bash scripting.
Stricklin, Raymond J wrote: I would, however, use -e instead of -f, because the system name is probably a directory, not a plain file. indeed, then why not use -d ? ok r. Both good points -- use the operator best suited to the task. If you want to make *sure* it's a file, use -f; if directory, use -d, if you don't care if it's a file, directory, link, socket, door, device, block or character special, etc, use -e -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390
Re: I am missing something basic with bash scripting.
> -Original Message- > From: Linux on 390 Port [mailto:[EMAIL PROTECTED] On > Behalf Of James Melin > Sent: Thursday, September 06, 2007 3:53 PM > To: LINUX-390@VM.MARIST.EDU > Subject: I am missing something basic with bash scripting. > > > I am trying to get away from hard coded server names in a > script using case for valid name check > > This works but is not good because as soon as you add a new > server to the NFS mountpoint list the script this is from has > to be changed. > > case $target_system in > abinodji | calhoun | itasca | nokomis | pepin | phalen | > vadnais | bemidji | millpond | mudlake | terrapin | hadley | > hyland ) parm_1="valid";; > esac > > > So I tried several variants of this: > > space=" " > delim=" | " > raw_list=`ls /clamscan/servers` #read list of mountpoints > cooked_list=$(echo $raw_list | sed -e "s:$space:$delim:g") > #replace space with case-happy delimiters > echo "Raw list = "$raw_list > echo "cooked list = "$cooked_list > case $target_system in > $cooked_list ) parm_1="valid" ;; > esac > > But even though the display of 'cooked_list' seems to be what > I want it to be, this never returns a match. > > Anyone see where I missed the turnip truck on this? I cannot answer your question. Perhaps the "case" does not allow the delimiters with a shell variable? I don't know. the following should work in place of the "case" construct, however. It has more overhead, but should work. echo ${raw_list} | egrep -q "\<${target_system}\>" && parm_1="valid" -- John McKown Senior Systems Programmer HealthMarkets Keeping the Promise of Affordable Coverage Administrative Services Group Information Technology The information contained in this e-mail message may be privileged and/or confidential. It is for intended addressee(s) only. If you are not the intended recipient, you are hereby notified that any disclosure, reproduction, distribution or other use of this communication is strictly prohibited and could, in certain circumstances, be a criminal offense. If you have received this e-mail in error, please notify the sender by reply and delete this message without copying or disclosing it. -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390
Re: I am missing something basic with bash scripting.
Mark Post wrote: If that doesn't help, then put a "set -x" right after the #!/bin/sh line, and send the output, along with the command invocation. or put "-x" on the shebang line: #! /bin/sh -x -- Carnegie Institution - At the Frontiers of Science Larry Ploetz Systems Administrator Carnegie Institution of Washington Department of Plant Biology, TAIR 650 325 1521 x 296 [EMAIL PROTECTED] -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390
Re: I am missing something basic with bash scripting.
> On 9/6/2007 4:31 PM, Edmund R. MacKenty wrote: > > Note that I'm using $(...) instead of backticks. Backticks are evil! > But I'm curious: why are backticks evil? (I didn't know about the > "$(command)" trick; I've been using backticks for a long time. I learn > something new every day!) Some uppity young whippersnappers think the $() syntax is easier to understand and convey to newbies, and are less subject to bonehead editors replacing them with normal single quotes. Me, I just think they're justifiable revenge on AT&T for the 3B2 and SVR1. -- db -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390
Re: I am missing something basic with bash scripting.
Fargusson.Alan wrote: The problem is that bash takes cooked_list as a single token in the case statement. It matches the entire list of systems, and not each member of the list. I don't know of any way around this. You will probably need to do another for loop on raw_list and check for a match in the loop. This is where eval comes in handy: larry$ bash -c 'set -x; list="a|b|c"; t=a; eval "case $t in ( $list ) echo one;; b ) echo two;; esac' + list='a|b|c' + t=a + eval 'case a in ( a|b|c ) echo one;; b ) echo two;; esac' ++ case a in ++ echo one one (although James would still have the problem of one system name being a subset of another system name.) -- Carnegie Institution - At the Frontiers of Science Larry Ploetz Systems Administrator Carnegie Institution of Washington Department of Plant Biology, TAIR 650 325 1521 x 296 [EMAIL PROTECTED] -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390
Re: I am missing something basic with bash scripting.
Adam Thornton wrote: Hey, can we digress a little, and talk about Very Large Services, Hardware, and Software Companies that *really* ought to know better, who actually don't appear to know that the things after the "http:" are forward, rather than back, slashes? Yeah. Got one of those *today*, while downloading something. Was not pleased. May be displeased enough to file a bug report about it. Trivial to fix, of course, but did mean that I had to type in the URL rather than, you know, click on it (well, to be fair, in my case, tab to it and hit enter). I assume it works with IE (surely someone tested their site with SOME browser, right?). And no, the company who did this was *not*, in fact, Microsoft. Can we name names, Adam? -- Cheers John -- spambait [EMAIL PROTECTED] [EMAIL PROTECTED] Please do not reply off-list -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390
Re: I am missing something basic with bash scripting.
On Sep 6, 2007, at 10:56 PM, John Summerfield wrote: David Boyes wrote: On 9/6/2007 4:31 PM, Edmund R. MacKenty wrote: Note that I'm using $(...) instead of backticks. Backticks are evil! But I'm curious: why are backticks evil? (I didn't know about the "$(command)" trick; I've been using backticks for a long time. I learn something new every day!) Some uppity young whippersnappers think the $() syntax is easier to understand and convey to newbies, and are less subject to bonehead editors replacing them with normal single quotes. Settle down there, boy! Hey, can we digress a little, and talk about Very Large Services, Hardware, and Software Companies that *really* ought to know better, who actually don't appear to know that the things after the "http:" are forward, rather than back, slashes? Yeah. Got one of those *today*, while downloading something. Was not pleased. May be displeased enough to file a bug report about it. Trivial to fix, of course, but did mean that I had to type in the URL rather than, you know, click on it (well, to be fair, in my case, tab to it and hit enter). I assume it works with IE (surely someone tested their site with SOME browser, right?). And no, the company who did this was *not*, in fact, Microsoft. Adam -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390
Re: I am missing something basic with bash scripting.
David Boyes wrote: On 9/6/2007 4:31 PM, Edmund R. MacKenty wrote: Note that I'm using $(...) instead of backticks. Backticks are evil! But I'm curious: why are backticks evil? (I didn't know about the "$(command)" trick; I've been using backticks for a long time. I learn something new every day!) Some uppity young whippersnappers think the $() syntax is easier to understand and convey to newbies, and are less subject to bonehead editors replacing them with normal single quotes. Settle down there, boy! -- Cheers John aka Santa -- spambait [EMAIL PROTECTED] [EMAIL PROTECTED] Please do not reply off-list -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390
Re: I am missing something basic with bash scripting.
I hadn't known about the $(...) function either until yesterday. So I've learned MANY interesting tricks just by asking that simple question (many thanks to everyone). I have hated the back-tik thing as well as it's really inelegant however it was all I knew. -J Adam Thornton <[EMAIL PROTECTED]> Sent by: Linux on 390 Port To LINUX-390@VM.MARIST.EDU cc 09/06/2007 05:13 PM Subject Re: I am missing something basic with bash scripting. Please respond to Linux on 390 Port On Sep 6, 2007, at 2:56 PM, Eric Chevalier wrote: > On 9/6/2007 4:31 PM, Edmund R. MacKenty wrote: >> Note that I'm using $(...) instead of backticks. Backticks are evil! > The InList() function is slick; I like it! > > But I'm curious: why are backticks evil? (I didn't know about the > "$(command)" trick; I've been using backticks for a long time. I learn > something new every day!) Backticks don't nest (without extensive and tricky escaping). $() does. Adam -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390 -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390
Re: I am missing something basic with bash scripting.
On Thursday 06 September 2007 18:09, Stricklin, Raymond J wrote: >> I would, however, use -e instead of -f, because the system >> name is probably a directory, not a plain file. > >indeed, then why not use -d ? Because -e allows the script to neither know nor care what type of file is there, just that a directory entry in /clamscan/servers with the desired name exists. I consider avoiding unnecessary dependencies or knowledge in functions a basic design principle, which allows code to be as general as possible. - MacK. - Edmund R. MacKenty Software Architect Rocket Software, Inc. Newton, MA USA -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390
Re: I am missing something basic with bash scripting.
On Sep 6, 2007, at 11:29 PM, John Summerfield wrote: Adam Thornton wrote: Hey, can we digress a little, and talk about Very Large Services, Hardware, and Software Companies that *really* ought to know better, who actually don't appear to know that the things after the "http:" are forward, rather than back, slashes? Yeah. Got one of those *today*, while downloading something. Was not pleased. May be displeased enough to file a bug report about it. Trivial to fix, of course, but did mean that I had to type in the URL rather than, you know, click on it (well, to be fair, in my case, tab to it and hit enter). I assume it works with IE (surely someone tested their site with SOME browser, right?). And no, the company who did this was *not*, in fact, Microsoft. Can we name names, Adam? Not until I contact them and ask them to please fix it. No point in embarrassing them if they make a speedy repair. Adam -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390
Re: I am missing something basic with bash scripting.
You could do something else entirely, like: larry$ a=a larry$ echo $list a|b|c larry$ [[ $list =~ $a ]] && echo hi || echo ho hi larry$ a=d larry$ [[ $list =~ $a ]] && echo hi || echo ho ho or [[ "$(ls /clamscan/servers)" =~ $target_system ]] && parm_1="valid" (assuming no system name is a subset of another system name. Otherwise: [[ "$(ls /clamscan/servers)" =~ " $target_system " ]] && parm_1="valid" to ensure $target_system matches exactly and all of one file name in /clamscan/servers, but the $target_system token has to be in the first column. or, of course, you could go the direct route: [[ -f /clamscan/servers/$target_system ]] && parm_1="valid" James Melin wrote: I am trying to get away from hard coded server names in a script using case for valid name check This works but is not good because as soon as you add a new server to the NFS mountpoint list the script this is from has to be changed. case $target_system in abinodji | calhoun | itasca | nokomis | pepin | phalen | vadnais | bemidji | millpond | mudlake | terrapin | hadley | hyland ) parm_1="valid";; esac So I tried several variants of this: space=" " delim=" | " raw_list=`ls /clamscan/servers` #read list of mountpoints cooked_list=$(echo $raw_list | sed -e "s:$space:$delim:g") #replace space with case-happy delimiters echo "Raw list = "$raw_list echo "cooked list = "$cooked_list case $target_system in $cooked_list ) parm_1="valid" ;; esac But even though the display of 'cooked_list' seems to be what I want it to be, this never returns a match. Anyone see where I missed the turnip truck on this? -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390 -- Carnegie Institution - At the Frontiers of Science Larry Ploetz Systems Administrator Carnegie Institution of Washington Department of Plant Biology, TAIR 650 325 1521 x 296 [EMAIL PROTECTED] -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390
Re: I am missing something basic with bash scripting.
I wrote: larry$ bash -c 'set -x; list="a|b|c"; t=a; eval "case $t in ( $list ) echo one;; b ) echo two;; esac' Not sure if anyone's interested in this technique, but if you do try the above, it won't work -- some email client/server and/or copy-and-paste messed it up. It should be: |bash -c 'set -x; list="a|b|c"; t=a; eval "case $t in ( $list ) echo one;; b ) echo two;; esac"' |or, shorter and more verbose: | bash -xvc 'list="a|b|c"; t=a; eval "case $t in ( $list ) echo one;; b ) echo two;; esac"' | Thanks, - Larry -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390
Re: I am missing something basic with bash scripting.
James Melin wrote: I hadn't known about the $(...) function either until yesterday. So I've learned MANY interesting tricks just by asking that simple question (many thanks to everyone). I have hated the back-tik thing as well as it's really inelegant however it was all I knew. Add this one to your toolkit too:-) People here have been doing arithmetic using $(()) which is fine, but only does integers. Sometimes one wants a decimal|floating point, so this can often be used: 06:55 [EMAIL PROTECTED] ~]$ echo 'scale=4;(14595.470+200.00)/4331.00' | bc 3.4161 06:55 [EMAIL PROTECTED] ~]$ I often do that for simple financial calculations (that's one of them). For more, man bc -- Cheers John -- spambait [EMAIL PROTECTED] [EMAIL PROTECTED] Please do not reply off-list -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390
Re: I am missing something basic with bash scripting.
John Summerfield wrote: People here have been doing arithmetic using $(()) which is fine, but only does integers. Sometimes one wants a decimal|floating point, so this can often be used: 06:55 [EMAIL PROTECTED] ~]$ echo 'scale=4;(14595.470+200.00)/4331.00' | bc 3.4161 06:55 [EMAIL PROTECTED] ~]$ Or, if you prefer RPN: $ dc -e '4k 14595.470 200.00 + 4331.00 / p' 3.4161 -- Carnegie Institution - At the Frontiers of Science Larry Ploetz Systems Administrator Carnegie Institution of Washington Department of Plant Biology, TAIR 650 325 1521 x 296 [EMAIL PROTECTED] -- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390