![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to check directory exist on servers | weonpc | Shell Programming and Scripting | 2 | 03-06-2008 06:29 AM |
| Check if certain files exist in a directory, if not add name to a textfile | SunnyK | Shell Programming and Scripting | 1 | 02-07-2008 09:21 AM |
| how to check if directory/file exist using c/c++ | steven88 | High Level Programming | 2 | 01-03-2006 02:55 AM |
| how to check if directory/file exist using c/c++ | steven88 | Shell Programming and Scripting | 1 | 01-02-2006 10:45 PM |
| how to check if the file exist or not? | gusla | UNIX for Dummies Questions & Answers | 3 | 03-27-2002 10:56 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
check the directory exist
I have the below script to check whether directory is exist or not , now I sure the directory /abc NOT exist , but when run the script , it still pop the result is "the directory exist" , could suggest what is wrong ? thx
ll -d /abc > /dev/null 2>&1 if [ $? = 0 ] then echo "the directory exist !!" else echo "the directory not exist !!" fi |
|
||||
|
FYI ust:
if [ -d $dir ] then ... fi is actually using the 'test' command. To find out what you can do with the test command then type: 'man test' You may also write the above as: if test -d $dir then ... fi or even use the test command on the comand line thus: >test -d $dir >echo $? Also I would recommend shell variables to be quoted in this context: if [ -d "$dir" ] ... to avoid any command line errors with the test command! i.e. if $dir were emtpy and you did if [ -d $dir ], then you would really be running: 'test -d' and the test command would complain. Hope this helps. MBB |
|
||||
|
Check if a directory exists
Hello:
Can someone please help me figure out what is wrong here, my script does not move on to the "else" part even though there is no .ssh directory on my remote server: $more putkey.sh #!/bin/ksh for server in `cat list` do if [ -d /.ssh ]; then cat $HOME/.ssh/id_rsa.pub |ssh $server ' cat >> .ssh/authorized_keys && echo "key copied"' else cat $HOME/.ssh/id_rsa.pub |ssh $server ' mkdir .ssh && cat >> .ssh/authorized_keys && echo "key copied"' fi done $./putkey.sh Password: sh: .ssh/authorized_keys: cannot create The script works if the else part is executed: $cat $HOME/.ssh/id_rsa.pub |ssh myserver ' mkdir .ssh && cat >> .ssh/authorized_keys && echo "key copied"' Password: key copied |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|