some tips about shell variables
2014-05-18 21:44
399 查看
1. 显示变量的长度,即${#var}
iubuntu@ubuntu:~$ aa="abc defg"
iubuntu@ubuntu:~$ echo ${#aa}
8
2. 查看当前正在使用shell的版本:
iubuntu@ubuntu:~$ echo $0
bash
iubuntu@ubuntu:~$ echo $SHELL
/bin/bash
3. 判断当前当前运行脚本是不是具有root权限:
#!/bin/bash
#filename: root.sh
if [ $UID -ne 0 ]; then
echo non root user
else
echo root user
fi
在运行sh root.sh过程中,出现了[: 7: -ne: unexpected operator,网上查了一下
因为ubuntu默认的sh是连接到dash的,又因为dash跟bash的不兼容所以出错了,解决办法有两种:
1)用bash root.sh来代替sh root.sh
2)修改sh默认连接到bash,sudo dpkg-reconfigure dash,选择no
iubuntu@ubuntu:~$ aa="abc defg"
iubuntu@ubuntu:~$ echo ${#aa}
8
2. 查看当前正在使用shell的版本:
iubuntu@ubuntu:~$ echo $0
bash
iubuntu@ubuntu:~$ echo $SHELL
/bin/bash
3. 判断当前当前运行脚本是不是具有root权限:
#!/bin/bash
#filename: root.sh
if [ $UID -ne 0 ]; then
echo non root user
else
echo root user
fi
在运行sh root.sh过程中,出现了[: 7: -ne: unexpected operator,网上查了一下
因为ubuntu默认的sh是连接到dash的,又因为dash跟bash的不兼容所以出错了,解决办法有两种:
1)用bash root.sh来代替sh root.sh
2)修改sh默认连接到bash,sudo dpkg-reconfigure dash,选择no
相关文章推荐
- Shell - Some useful tips to work with Shell
- some tips about python Four
- Some useful tips about sox rec
- Some Tips About Layout Resource
- Some tips about how to reverse Array with C#
- Some tips about python Seven
- Some tips about crawling large external data with bcs connector
- Some Tips about Interbase
- Some tips about Abstract base classes and pure virtual functions
- some tips about python
- some tips about python default value....
- [bash] Some Tips for the Bourne Again Shell
- some tips about sys.objects table
- Some tips about SoapUI project
- Some Tips and Tricks about Qt
- Some basic tips about 'git stash'
- Some Tips and Tricks about Qt
- some tips about vector in C++ STL
- Some tips about the C++(自己看的,很乱)
- Some tips about argument in python