check, that a script is in a folder

2011-01-05 Thread S Mathias
$ echo ${PWD##*/}
somefolder
$ if ${PWD##*/} -eq asdf  /dev/null; then echo this is the asdf folder; 
else exit 1; fi
bash: notthatfolder: command not found...
this is the asdf folder
$ 


So i just want to check that i'm in an exact folder. e.g.: asdf

What's wrong with my one-liner?

I just want to check, that a script is in a folder, and if it isn't, then it 
exits


  


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/434149.43513...@web121408.mail.ne1.yahoo.com



Re: check, that a script is in a folder

2011-01-05 Thread Didar Hossain
On Wed, Jan 05, 2011 at 02:27:39AM -0800, S Mathias wrote:
 $ echo ${PWD##*/}
 somefolder
 $ if ${PWD##*/} -eq asdf  /dev/null; then echo this is the asdf 
 folder; else exit 1; fi

if [ ${PWD##*/} == asdf ]; then echo this is the asdf folder; else exit 
1; fi


Why not simple use:

if [ -e $SCRIPT ]; then
  echo File exists;
else
  echo File does not exist;
fi



Regards,
Didar


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20110105104413.ga2...@didar-laptop



Re: check, that a script is in a folder

2011-01-05 Thread Pascal Hambourg
Hello,

S Mathias a écrit :
 $ if ${PWD##*/} -eq asdf  /dev/null; then echo this is the asdf 
 folder; else exit 1; fi
 bash: notthatfolder: command not found...
 this is the asdf folder
 
 What's wrong with my one-liner?

Two mistakes :
1) if expects a command, not a boolean expression. Use test
expression or [ expression ] to evaluate the expression.
2) -eq is the equal operator for numeric integers, not strings. Use
= for string comparison.


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/4d244c40.7040...@plouf.fr.eu.org



Re: check, that a script is in a folder

2011-01-05 Thread S Mathias
thank you, the:

if ! [ ${PWD##*/} == asdf ]; then echo error: not the asdf dir; exit 1; fi

worked! :)

--- On Wed, 1/5/11, Pascal Hambourg pascal.m...@plouf.fr.eu.org wrote:

 From: Pascal Hambourg pascal.m...@plouf.fr.eu.org
 Subject: Re: check, that a script is in a folder
 To: debian-user@lists.debian.org
 Date: Wednesday, January 5, 2011, 10:47 AM
 Hello,
 
 S Mathias a écrit :
  $ if ${PWD##*/} -eq asdf  /dev/null; then echo
 this is the asdf folder; else exit 1; fi
  bash: notthatfolder: command not found...
  this is the asdf folder
  
  What's wrong with my one-liner?
 
 Two mistakes :
 1) if expects a command, not a boolean expression. Use
 test
 expression or [ expression ] to evaluate
 the expression.
 2) -eq is the equal operator for numeric integers, not
 strings. Use
 = for string comparison.
 
 
 -- 
 To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org
 
 with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
 Archive: http://lists.debian.org/4d244c40.7040...@plouf.fr.eu.org
 
 





--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/738152.73961...@web121407.mail.ne1.yahoo.com



Re: check, that a script is in a folder

2011-01-05 Thread Pascal Hambourg
S Mathias a écrit :
 
 if ! [ ${PWD##*/} == asdf ]; then echo error: not the asdf dir; exit 1; 
 fi

Note that == is a bashism. = is more portable across other shells
such as dash.


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/4d246485.9080...@plouf.fr.eu.org