Where is wrong with my default value?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Where is wrong with my default value?
# 1  
Old 12-18-2012
Where is wrong with my default value?

Code:
lyang0@lyang0-OptiPlex-755:/tmp$ ./fg.sh 
...............................
ssh to the guest .....
...............................
./fg.sh: 18: :ls: not found


Code:
lyang0@lyang0-OptiPlex-755:/tmp$ cat fg.sh 
#!/bin/sh
DEFAULT_CMD="ls /boot/"
ssh_to_guest()
{
        echo "..............................."
        echo "ssh to the guest ....."
        echo "..............................."
    CMD="$1"
    :${CMD:=$DEFAULT_CMD}
        if ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@128.224.165.205 "${CMD}";then
                echo "pass"
        else
                echo "fail"
        fi
        

}
ssh_to_guest

# 2  
Old 12-18-2012
Try changing:
Code:
    CMD="$1"
    :${CMD:=$DEFAULT_CMD}

to:
Code:
    CMD=${1:-$DEFAULT_CMD}

# 3  
Old 12-18-2012
Quote:
Originally Posted by Don Cragun
Try changing:
Code:
    CMD="$1"
    :${CMD:=$DEFAULT_CMD}

to:
Code:
    CMD=${1:-$DEFAULT_CMD}

I changed to yours

then run

Code:
./fg.sh ifconfig

it doesn't run ifconfig but still using default value
# 4  
Old 12-18-2012
Quote:
Originally Posted by yanglei_fage
I changed to yours

then run

Code:
./fg.sh ifconfig

it doesn't run ifconfig but still using default value
Sorry about that. Also change the last line from:
Code:
 ssh_to_guest

to:
Code:
 ssh_to_guest "$1"

Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. Post Here to Contact Site Administrators and Moderators

Whether anything went wrong ?

Hi could see all the post with this old color scheme ( legacy (dark) vBulletin color scheme (unsupported)) except this post, please look at the screenshot . Looks like url parsing also some problem is there getting "Page not found" error. -- Akshay --edit-- screenshot is there in album... (18 Replies)
Discussion started by: Akshay Hegde
18 Replies

2. Shell Programming and Scripting

Why result is wrong here ? whether break statement is wrong ?

Hi ! all I am just trying to check range in my datafile pls tell me why its resulting wrong admin@IEEE:~/Desktop$ cat test.txt 0 28.4 5 28.4 10 28.4 15 28.5 20 28.5 25 28.6 30 28.6 35 28.7 40 28.7 45 28.7 50 28.8 55 28.8 60 28.8 65 28.1... (2 Replies)
Discussion started by: Akshay Hegde
2 Replies

3. Shell Programming and Scripting

I can't get what I'm doing wrong!

I am making a shell script that will have "shortcuts" to do different tasks and I can't get what I'm doing wrong (this is just a test script) read cake if then echo "1 it is" fiit outputs: 1: : bad variable namecake test.sh: 27: test.sh: Syntax error: end of file unexpected (expecting... (22 Replies)
Discussion started by: kitay
22 Replies

4. UNIX for Dummies Questions & Answers

What is wrong in here ???

]#PATH=/usr/bin:/etc:/bin:/boot/grub:/boot/grup/bin: /boot/solaris/bin:/sbin:/usr/openwin/bin:/usr/5bin://usr/X11/bin:/usr/apache/bin:/usr/apache2/bin:/usr/appserver/bin:... (9 Replies)
Discussion started by: microbot
9 Replies
Login or Register to Ask a Question