Hi everybody.
I'm trying to work something for testing based on a relative filename the ../ or ./ of a directory:
example
Code:
test \(echo '../'| grep -q '^\.\{1,1\}'\) -a \(echo '../ | grep -q '^\.\{2,2\}'\)
would give true
Code:
test \(echo './'| grep -q '^\.\{1,1\}'\) -a \(echo './ | grep -q '^\.\{2,2\}'\)
and this one would give false
For example if you issue
Code:
echo '../'| grep '^\.\{1,1\}'
../ (two dots, and the first dot matched by grep)
if you issue
Code:
echo './'| grep '^\.\{2,2\}'
will not match the two points at the beginning
Other alternative way
Code:
[ echo '../'| grep -q '^\.\{1,1\} ] && [ echo '../'| grep -q '^\.\{2,2\} ] && echo true
errors are:
Code:
bash: [: missing `]'
grep: [ ó ^[ desemparejados
Notice I'm using the -q option to avoid output of grep. Logic would be applied based on exit status of grep of course.
Anyone would be so kind to tell me what I'm doing wrong (i guess the problem is with the pipes).
I also can stop whining, save the exit status on variables and later make a variable comparison (that is my last resort)?
A B A&B
0 0 0
0 1 0
1 0 0
1 1 1
http://www.gnu.org/software/bash/man...ell-Expansions
I'm using this guides:
http://tldp.org/LDP/Bash-Beginners-G...ct_07_01_02_01
http://tldp.org/LDP/abs/html/ops.html
I'm no programmer and just a beginner ...
Not much experience in this.
Thanks in advance
Bookmarks