shell里面如何传递参数: sh test.sh zhang 20 那test.sh里面咋接受参数呢? #!/usr/bin/env sh name=$1 age=$2 echo "name is ${name} & age is ${age}" 输出:name is yaochun & age is 20 $# 获取参数的个数 $* 获取全部参数 $@ 获取全部参数 扩展阅读: http://bbs.chinaunix.net/thread-1135876-1-
shell脚本处理长参数的模板 一个shell模板,处理命令行参数,支持长短参数: #!/bin/bash # # FILE: kvm-clone-v2.sh # # DESCRIPTION: Clone a RHEL5.4/RHEL6 kvm guest on ubuntu14.04 host superv. # This shell is used for cloning RHEL5.4 or RHEL6.x KVM guest. # Note this shell is only test
1.判断变量 read -p "input a word :" word if [ ! -n "$word" ] ;then echo "you have not input a word!" else echo "the word you input is $word" fi 2.判断输入参数 #!/bin/bash if [ ! -n "$1" ] ;then echo "you have n