Re: [CentOS] C5 BASH IF

2015-02-14 Thread Chris Adams
Once upon a time, Les Mikesell said: > I think that is still an oversimplification because more than > expansion is involved and the order related to other steps. When does > it do i/o redirection; which things happen before/during starting > subshells/pipes; what if you use 'eval', etc.? Try th

Re: [CentOS] C5 BASH IF

2015-02-14 Thread PatrickD Garvey
On Sat, Feb 14, 2015 at 11:28 AM, Les Mikesell wrote: > On Sat, Feb 14, 2015 at 1:13 PM, Robert Nichols > wrote: >> >>> But it is not 'just' expansions. You need to know the full order of >>> operations with all the steps - word splitting, quote removal, i/o >>> redirection, groupings, etc., so

Re: [CentOS] C5 BASH IF

2015-02-14 Thread Les Mikesell
On Sat, Feb 14, 2015 at 1:13 PM, Robert Nichols wrote: > >> But it is not 'just' expansions. You need to know the full order of >> operations with all the steps - word splitting, quote removal, i/o >> redirection, groupings, etc., some of which is repeated over the line >> after some of the othe

Re: [CentOS] C5 BASH IF

2015-02-14 Thread Robert Nichols
On 02/14/2015 12:03 PM, Les Mikesell wrote: On Sat, Feb 14, 2015 at 11:36 AM, J Martin Rushton wrote: To understand it completely you need to know the order of operations as the shell makes multiple passes over the line, parsing, processing metacharacters, and expanding variables. And I don

Re: [CentOS] C5 BASH IF

2015-02-14 Thread Les Mikesell
On Sat, Feb 14, 2015 at 11:36 AM, J Martin Rushton wrote: > >> To understand it completely you need to know the order of >> operations as the shell makes multiple passes over the line, >> parsing, processing metacharacters, and expanding variables. And >> I don't know where to find a concise de

Re: [CentOS] C5 BASH IF

2015-02-14 Thread J Martin Rushton
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 14/02/15 16:53, Les Mikesell wrote: > To understand it completely you need to know the order of > operations as the shell makes multiple passes over the line, > parsing, processing metacharacters, and expanding variables. And > I don't know wh

Re: [CentOS] C5 BASH IF

2015-02-14 Thread Chris Adams
Once upon a time, Les Mikesell said: > On Fri, Feb 13, 2015 at 11:54 PM, Always Learning wrote: > >> 16 if [ $file = "law00css" ] > > You still missed the part about quoting variables. You quote plain > strings to hold embedded spaces together (or single-quotes to avoid > parsing metacharacter

Re: [CentOS] C5 BASH IF

2015-02-14 Thread Robert Nichols
On 02/13/2015 11:47 PM, Always Learning wrote: I re-ran the script with 'set -x' for 16 if [ $file='law00css' ] 17 then 18echo $file 19echo "css" 20 else 21echo "no css" 22 fi and received:- + '[' law45p07a01=law00css ']' + echo law45p07a01 law45p07a01 + echo css css

Re: [CentOS] C5 BASH IF

2015-02-14 Thread Les Mikesell
On Fri, Feb 13, 2015 at 11:54 PM, Always Learning wrote: > >> And third, you generally should use >> double quotes around variables in tests so they continue to exist as >> an empty string if the variable happens to not be set. > > Thanks for that. I assumed if test 1 worked, so would test 2. > >

Re: [CentOS] C5 BASH IF

2015-02-14 Thread J Martin Rushton
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Try using [[ and ]] rather than [ and ]. Under BASH the double form are reserved words with special meaning to the shell whereas the single form are just a synonym for test. Parsing and splitting rules are different, in particular word splitting and

Re: [CentOS] C5 BASH IF

2015-02-13 Thread Always Learning
On Fri, 2015-02-13 at 23:46 -0600, Les Mikesell wrote: > I think you are missing some very basic concepts here. First, the > shell likes to parse things separated by white space. Second, [ is a > synonym for test which is a build-in version of /bin/test, so try 'man > test' for the syntax of te

Re: [CentOS] C5 BASH IF

2015-02-13 Thread Always Learning
On Sat, 2015-02-14 at 05:26 +, Always Learning wrote: > NON-WORKING second comparison > > 15 if [ $file='law00.css' ] > 16 then > 17file=$dir/$file > 18echo "css" > 19 else > 20file=$dir/$file\.php > 21echo "no css" > 22 fi > 23 #-

Re: [CentOS] C5 BASH IF

2015-02-13 Thread Les Mikesell
On Fri, Feb 13, 2015 at 11:26 PM, Always Learning wrote: > Being new to some aspects of BASH, I tried to reduce the quantity of > scripts by introducing a comparison test into an existing working > script. > > The script refused to work until I placed [ ] around the actual test. > The second test,

[CentOS] C5 BASH IF

2015-02-13 Thread Always Learning
Being new to some aspects of BASH, I tried to reduce the quantity of scripts by introducing a comparison test into an existing working script. The script refused to work until I placed [ ] around the actual test. The second test, in the same script, misfunctioned until I removed the [ ] around the