bash script, need help ! Please!

bash script, need help ! Please!

Post by Leo » Wed, 03 Jan 2001 23:00:37



Hello

      I've encountered some difficulty while writing my own bash
program, the situation is: I want to know wheather a directory is Empty
or not, if it is, it will echo a message i.e.  " Directory Empty ", and
if it's not, it will ls th files. I wonde how it could be achieved?

 Below I tried putting the ls result into a TEMPVAR, and check if its
NULL, however it didn't work. I wonder where i did wrong or is that way
possible? Any help would be greatly appreciated. Thank you !

# $RECY=a directory

 TEMPVAR=`ls $RECY`
 if TEMPVAR=NULL
 then
   echo "There are currently no files in the directory"
else
  ls $RECY
fi

Thank you very much,
   Leo

 
 
 

bash script, need help ! Please!

Post by Sven Burgene » Thu, 04 Jan 2001 00:32:06



>       I've encountered some difficulty while writing my own bash
> program, the situation is: I want to know wheather a directory is Empty
> or not, if it is, it will echo a message i.e.  " Directory Empty ", and
> if it's not, it will ls th files. I wonde how it could be achieved?
>  Below I tried putting the ls result into a TEMPVAR, and check if its
> NULL, however it didn't work. I wonder where i did wrong or is that way
> possible? Any help would be greatly appreciated. Thank you !

I get your idea. How about the following?

--8<--
if [ "$(ls $DIRECTORY)" == "" ]
then
  echo "empty"
else
  echo "not empty"
fi
--8<--

That should work ok.

Quote:> Thank you very much,

HTH
Sven

 
 
 

bash script, need help ! Please!

Post by Bill Unr » Thu, 04 Jan 2001 03:58:56



]Hello

]      I've encountered some difficulty while writing my own bash
]program, the situation is: I want to know wheather a directory is Empty
]or not, if it is, it will echo a message i.e.  " Directory Empty ", and
]if it's not, it will ls th files. I wonde how it could be achieved?

] Below I tried putting the ls result into a TEMPVAR, and check if its
]NULL, however it didn't work. I wonder where i did wrong or is that way
]possible? Any help would be greatly appreciated. Thank you !

]# $RECY=a directory

] TEMPVAR=`ls $RECY`
] if TEMPVAR=NULL

This sets TEMPVAR to the value NULL
Try
if [ "$TEMPVAR" == "" ]
] then
]   echo "There are currently no files in the directory"
]else
]  ls $RECY
]fi

]Thank you very much,
]   Leo

 
 
 

bash script, need help ! Please!

Post by Daniel Novotn » Thu, 04 Jan 2001 00:00:45



> Hello

>       I've encountered some difficulty while writing my own bash
> program, the situation is: I want to know wheather a directory is Empty
> or not, if it is, it will echo a message i.e.  " Directory Empty ", and
> if it's not, it will ls th files. I wonde how it could be achieved?

>  Below I tried putting the ls result into a TEMPVAR, and check if its
> NULL, however it didn't work. I wonder where i did wrong or is that way
> possible? Any help would be greatly appreciated. Thank you !

> # $RECY=a directory

>  TEMPVAR=`ls $RECY`
>  if TEMPVAR=NULL

   ^^^^^^^^^^^^^^^
there should be
if [ -z $TEMPVAR ]
or
if test -z $TEMPVAR
(the same)
see "man test"

- Show quoted text -

Quote:>  then
>    echo "There are currently no files in the directory"
> else
>   ls $RECY
> fi

> Thank you very much,
>    Leo

 
 
 

1. BASH BASH BASH BASH BASH BASH BASH BASH BASH BASH

Is there a proper fixed bash on any of the FTP sites out there?

I know there bash is on the usual sites but I don't know if they are
bugged or not :(

Regards,

Neil.

--


------------------------------------| Edinburgh, EH14 2DE, United Kingdom
**Domino: There`s nothing you can do when you`re the next in line: Domino**

2. HOW: show kernel configuration and recognized devices

3. Bash Scripting problem... Please help

4. Setting up an Internal Modem

5. Help with Bash scripting please :)

6. Question about an unknown TCP/IP port

7. Need help with bash script to isolate a portion of an output

8. I've already had no further idea...

9. Passing option to bash script help needed

10. Need help wirh scripting arrays in bash

11. Need help on bash scripting

12. Keyboard shortcuts with Bash script -- Need HELP

13. Need help with an IF in a bash script