Results 1 to 2 of 2
I have a function that checks to see if a file is open or closed.
Code:
function check_file_status {
if [ -f "$1" ]; then
LSOF=$(lsof "$1")
else
unset LSOF
...
- 11-10-2010 #1
BASH .. if[] not working ..help out!
I have a function that checks to see if a file is open or closed.
I am trying to use that in another function within my bash script.Code:function check_file_status { if [ -f "$1" ]; then LSOF=$(lsof "$1") else unset LSOF fi if [ -n "$LSOF" ] ; then echo "open" else echo "closed" fi }
when I run the script though i get the following errorCode:if [$(check_file_status "$1$item") == 'open' ]; then echo "file is open" else echo "$1$item is close" fi
if i run with -x i see the followingCode:ftp_monitor.sh: line 77: [closed: command not found
Code:++ echo closed + '[closed' == open ']' ftp_monitor.sh: line 77: [closed: command not found
i have also tried the following in the if statment
and get the same results.Code:if ["$(check_file_status "$1$item")" == "open" ];
can anyone shed some light on what's happening?
Thanks for any help
CLast edited by pendal; 11-10-2010 at 06:36 PM. Reason: title change
- 11-11-2010 #2Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
Look carefully at the error message, noting that characters in:
are all together.Code:[closed
Use whitespace around "[" and "]".
The "[" is actually a command, namely test.
See man bash to learn more ... cheers, drlWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )


Reply With Quote