[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ls doesn't work in if statements in bash 4.3
From: |
billycongo |
Subject: |
Re: ls doesn't work in if statements in bash 4.3 |
Date: |
Thu, 27 Mar 2014 09:28:36 -0700 (PDT) |
User-agent: |
G2/1.0 |
On Wednesday, March 26, 2014 8:30:12 PM UTC-4, billy...@gmail.com wrote:
> I tested on bash 4.3 and 3.0
>
>
>
> testing]$ bash --version
>
> bash --version
>
> GNU bash, version 4.3.0(1)-release (x86_64-unknown-linux-gnu)
>
>
>
> In a directory I have:
>
>
>
> testing]$ ls -l
>
> total 16
>
> -rw-r--r-- 1 hpierce hpierce 77 Mar 26 20:09 dog1
>
> -rw-r--r-- 1 hpierce hpierce 77 Mar 26 20:09 dog2
>
> -rw-r--r-- 1 hpierce hpierce 77 Mar 26 20:09 dog3
>
> -rw-r--r-- 1 hpierce hpierce 0 Mar 26 20:07 dog4
>
> -rwxr-xr-x 1 hpierce hpierce 80 Mar 26 20:02 test
>
>
>
> dog1, dog2, and dog3 have content. dog4 is empty.
>
>
>
> test is a simple script:
>
>
>
> testing]$ cat test
>
> #!/bin/bash
>
> FILE=$1
>
> echo $FILE
>
> if [ ! -e $FILE ]
>
> then
>
> echo "Usage: $0 <file>"
>
> exit 1
>
> else
>
> echo $FILE exists
>
> fi
>
>
>
> Here's a regular run:
>
>
>
> testing]$ for f in *; do ./test $f; done
>
> dog1
>
> dog1 exists
>
> dog2
>
> dog2 exists
>
> dog3
>
> dog3 exists
>
> dog4
>
> dog4 exists
>
> test
>
> test exists
>
>
>
> Now I add a ls:
>
>
>
> testing]$ for f in `ls dog*`; do ./test $f; done
>
> dog1
>
> Usage: ./test <file>
>
> dog2
>
> Usage: ./test <file>
>
> dog3
>
> Usage: ./test <file>
>
> dog4
>
> Usage: ./test <file>
>
>
>
> So I moved it to an earlier version of bash
>
>
>
> testing]$ bash --version
>
> bash --version
>
> GNU bash, version 3.00.15(1)-release (x86_64-redhat-linux-gnu)
>
>
>
> testing]$ for f in `ls dog*`; do ./test $f; done
>
> dog1
>
> dog1 exists
>
> dog2
>
> dog2 exists
>
> dog3
>
> dog3 exists
>
> dog4
>
> dog4 exists
These restrictions that you talk about are important, but you don't seem to
hear me when I say "My filenames never have spaces". My directories never have
spaces. I am meticulous about my filesystems. On one hand I realize you think
you're being helpful to someone who has just started bash programming, but
since I've been at this for > 12 years it has gotten a little condescending. I
solved the issue myself about 10 minutes later. I thought it was interesting
that with the problematic dir_colors file I was unable to use 'ls' but 'find'
worked. I work as a system administrator so I understand that people are at
different levels in terms of technical knowledge. It's all about reading
comprehension. If you had read "My filenames never have spaces" part and
actually paid attention you would see that the problem had nothing to do with
spaces. But no. Everyone wants to show how smart they are that spaces can
mess things up. Wow! Thanks! My guess is that you'll breeze right past this
post and continue to give me helpful hints. Thanks guys!
--Snarky System Administrator (Is there any other kind?)
- Re: ls doesn't work in if statements in bash 4.3, (continued)
- Re: ls doesn't work in if statements in bash 4.3, Eduardo A . Bustamante López, 2014/03/27
- Re: ls doesn't work in if statements in bash 4.3, billycongo, 2014/03/27
- Re: ls doesn't work in if statements in bash 4.3, Greg Wooledge, 2014/03/27
- easier construction of arrays, Mike Frysinger, 2014/03/27
- Re: easier construction of arrays, Pierre Gaston, 2014/03/27
- Re: easier construction of arrays, Dan Douglas, 2014/03/27
- Re: easier construction of arrays, Mike Frysinger, 2014/03/27
- Re: easier construction of arrays, Dan Douglas, 2014/03/27
Re: ls doesn't work in if statements in bash 4.3, billycongo, 2014/03/27
Re: ls doesn't work in if statements in bash 4.3,
billycongo <=
Re: ls doesn't work in if statements in bash 4.3, billycongo, 2014/03/27