set的使用 (ex34.sh)

bash脚本设置系统信息并重置参数
本文介绍了一个bash脚本如何通过命令行参数接收输入,并使用`uname-a`命令获取系统信息。脚本将系统信息设置为参数值,然后重置参数到`uname-a`的输出结果,展示了一种在bash脚本中灵活处理系统信息的方法。
#!/bin/bash
# ex34.sh
# Script "set-test"

# Invoke this script with three command-line parameters,
# for example, "sh ex34.sh one two three".

echo
echo "Positional parameters before  set \`uname -a\` :"
echo "Command-line argument #1 = $1"
echo "Command-line argument #2 = $2"
echo "Command-line argument #3 = $3"


set `uname -a` # Sets the positional parameters to the output
               # of the command `uname -a`

echo
echo +++++
echo $_        # +++++
# Flags set in script.
echo $-        # hB
#                Anomalous behavior?
echo

echo "Positional parameters after  set \`uname -a\` :"
# $1, $2, $3, etc. reinitialized to result of `uname -a`
echo "Field #1 of 'uname -a' = $1"
echo "Field #2 of 'uname -a' = $2"
echo "Field #3 of 'uname -a' = $3"
echo \#\#\#
echo $_        # ###
echo

exit 0
[root@localhost shell]# ./ex34.sh one two three

Positional parameters before  set `uname -a` :
Command-line argument #1 = one
Command-line argument #2 = two
Command-line argument #3 = three

+++++
+++++
hB

Positional parameters after  set `uname -a` :
Field #1 of 'uname -a' = Linux
Field #2 of 'uname -a' = localhost.localdomain
Field #3 of 'uname -a' = 2.6.25-14.fc9.i686
###
###

[root@localhost shell]# uname -a
Linux localhost.localdomain 2.6.25-14.fc9.i686 #1 SMP Thu May 1 06:28:41 EDT 2008 i686 i686 i386 GNU/Linux

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值