# bash nested if/else if [ $choice -eq 1 ] ; then echo "You have chosen word: Bash" else if [ $choice -eq 2 ] ; then echo "You have chosen word: Scripting" else if [ $choice -eq 3 ] ; then echo "You have chosen word: Tutorial" else echo "Please make a choice between ...
test -f /etc/fstab ## true if a regular file test -h /etc/rc.local ## true if a symbolic link [ -x "$HOME/bin/hw" ] ## true if you can execute the file [[ -s $HOME/bin/hw ]] ## true if the file exists and is not empty 整数测试 整数之间的比较使用-eq、-ne、-gt...
Catkin tools installed successfully."fi}create_catkin_ws(){# Checkifworkspace existsif[ -e"$CATKIN_DIR/.catkin_workspace"] || [ -d"$CATKIN_DIR/.catkin_tools"]; thenecho"Catkin workspace detected at ~/catkin_ws"elseecho"Creating catkin workspace ...
@TJ Crowder我不确定`dirname $ 0`是一个问题,如果你将它分配给一个变量,然后用它来启动像`$ dir/script.sh`这样的脚本; 我想象这是90%的时间用于此类事情的用例.`./ script.sh`可以正常工作. (8认同) `$ 0`在源脚本(包括`bashrc`)中给出了错误的结果 (5认同) @TJ Crowder>但肯定有更好的方法...
configure是检查系统的库文件、类文件、依赖软件是否存在以及它们的版本是否满族需求,并根据实际检测结果生成Makefile的工具。一般是一堆bash命令的组合。通常也需要在这一步配置一些参数。最常用的就是指定软件的安装目录--prefix=/home/ct/soft/specific_name。 make则是具体的编译过程。编译的语句都写在了Makefile中...
cd /net || { echo "Can't read /net. Make sure you've logged in to the Samba network, and try again."; exit 1; } do_stuff more_stuff 注意,在{号和 echo 之间需要有一个空格,同时}之前要加上分号。 顺便提一下,如果你要在脚本里频繁改变当前目录,可以看看 pushd/popd/dirs 等命令,可能你...
-ne 不等于,如:if [ "a"−ne"b" ] -gt 大于,如:if [ "a"−gt"b" ] -ge 大于等于,如:if [ "a"−ge"b" ] -lt 小于,如:if [ "a"−lt"b" ] -le 小于等于,如:if [ "a"−le"b" ] < 小于(需要双括号),如:(("a"<"b")) ...
1 dir=/home/bozo 2 3 if cd "$dir" 2>/dev/null; then # "2>/dev/null" hides error message. 4 echo "Now in $dir." 5 else 6 echo "Can't change to $dir." 7 fiif命令将返回if后边的命令的退出码.与此相似,当在一个在使用与或列表结构的时候,test或中括号的使用,也并不一定非的...
if[[$foo="$bar"]] 如果你确实要执行模式匹配,聪明的做法是取一个更加有意义的变量名(例如 $patt),或者加上注释说明。 35. if [[ $foo =~ 'some RE' ]] 同上,如果 =~号右侧的值加上引号,它会散失特殊的正则表达式含义,而变成一个普通的字符串。
If the directory name is not exist in the current location then it will create the directory, otherwise the program will display error. #!/bin/bash echo "Enter directory name" read newdir `mkdir $newdir` Run the file with bash command. $ bash make_directory.sh Go to top Make directory...