22问答网
所有问题
当前搜索:
shell脚本内部变量的使用
Linux中执行
shell脚本的
4种方法总结
答:
查看PATH的内容可用 echo $PASH 命令。现在的/data/shell就不在环境
变量
PASH中的,所以必须加上./才可执行。方法二:以绝对路径的方式去执行bash
shell脚本
: /data/shell/hello.sh 方法三:直接
使用
bash 或sh 来执行bash shell脚本: cd /data/shell bash hello.sh 或者 cd /data/shell sh hello...
shell脚本
如何判断
变量
为数字?
答:
可以,不过不是bash实现的,是
使用
了grep的正则 if grep '^[[:digit:]]*$'<<< "$1";then echo "$1 is number."else echo 'no.'fi 方法3 if ["$1"-gt 0 ]2>/dev/null ;then echo "$1 is number."else echo 'no.'fi 方法4,case case "$1"in [1-9][0-9]*)echo "$...
Linux
Shell 脚本
编程最佳实践
答:
除了在行结束
使用
换行符,空格是源文件中唯一允许出现的空白字符。对从来没有用到的或者被注释的方法、
变量
等要坚决从代码中清理出去,避免过多垃圾造成干扰。Bash 是唯一被允许使用的可执行
脚本shell
。可执行文件必须以 #!/bin/bash 开始。请使用 set 来设置
shell的
选项,使得用 bash echo "Process...
shell
通过传入的参数名去取环境
变量
答:
shell脚本
中用$1取得第一个参数PARAM,再根据此
变量
名取得环境变量:eval echo \$$1 测试:a=3$ b=a$ eval echo \$$b3
shell
如何读取文件中
变量
值
答:
1 2 3 4 5 6 !/bin/bash
使用
方法:./script.sh filename a=$(sed -n '$p' $1 | awk -F"," '{print $1}')b=$(sed -n '1!P;N;$q;D' $1 | awk -F"," '{print $1}')echo $a echo $b
关于
shell脚本
互相传递
变量的
问题
答:
引用文件应该这样 . function.var 你的父
脚本
test1.sh中修改一下 !/bin/bash source 5.sh read aa export aa . test2.sh echo $bb echo "$cc"
使用
gedit编写特定功能的shell脚本,熟悉
shell脚本的变量
、表达式和流程...
答:
thenls $direlseecho -e "the $dir not exist."\nfisleep 1sh /home/test
shell
/custom.sh;;1)read -p 'please input the directory what you want to delete:' -t 11 dirif [ -d $dir ];thenrmdir $direlseecho -e "the $dir not exist."\nfisleep 1sh /home/testshell/custom....
bash如何在一个
脚本
里引用另一个脚本定义的
变量
?
答:
sub-
shell
执行完毕后返回parent-shell. sub-shell从parent-shell继承环境
变量
.但是sub-shell中的环境变量不会带回parent-shell exec (exec /directory/script.sh)exec与fork不同,不需要新开一个sub-shell来执行被调用的
脚本
. 被调用的脚本与父脚本在同一个shell内执行。但是
使用
exec调用一个新脚本以后...
我在
shell脚本的
循环里
使用
find查找文件,然后赋值给了
变量
$FILE,但是...
答:
NAME改成双引号:FILE=`find ./ -name "$NAME"`
shell脚本
中如何截取
变量的
前n个长度?
答:
展示echo $A | cut -c 1-8 或者echo $A | cut -b 1-8 传给
变量
:sh/ksh:param=`echo $A | cut -c 1-8`(字符截取)或者 param=`echo $A | cut -b 1-8`(字节截取)csh:set param=`echi $A | cut -c 1-8`或者 set param=`echi $A | cut -b 1-8`...
棣栭〉
<涓婁竴椤
4
5
6
7
9
10
8
11
12
13
涓嬩竴椤
灏鹃〉
其他人还搜