sh脚本之间参数传递

1.sh脚本之间参数传递:

a.sh
FILE=xxx
sh b.sh $FILE

b.sh
cp $1 /usr/local/

 

2.sh脚本给expect脚本传参

a.sh

#!/bin/sh
export DEBUG=true;
DEBUG_ECHO()
{
 if [ "$DEBUG" = "true" ]; then
  echo $@  
 fi
}
JENKINS_FILE_NAME=/home/grant/jenkins/jenkins.war
DEBUG_ECHO "$JENKINS_FILE_NAME"
START_CI_CMD=sudo java -jar $JENKINS_FILE_NAME
DEBUG_ECHO "$START_CI_CMD"
exec /usr/bin/expect /home/grant/Tools/sudo.expect $START_CI_CMD

 

b.expect

#!/usr/bin/expect
send_user "argc=$argc.\n"
send_user "[lindex $argv 0]\n"
if { $argc != 2 && $argc != 1 } {
    send_user "no para.\n"
    exit
}
set usercmd [lindex $argv 0]
set timeout 10
spawn ${usercmd}
expect "*password*:"
send "Realove777\r"
interact

posted @ 2012-06-22 21:06  Grant_688  阅读(1021)  评论(0编辑  收藏  举报