简体   繁体   English

unix中的shell脚本错误

[英]shell script error in unix

what does using 1# for a directory do here? 在目录中使用1#做什么?

cpfile=${1#/usr/newconfig} ls -l $cpfile | cpfile = $ {1#/ usr / newconfig} ls -l $ cpfile | read var1 echo var1 读var1 echo var1

I am tryiing to understand the script, but I cannot find any resource that would help me ascertain the meaning of this command. 我正在尝试理解脚本,但我找不到任何可以帮助我确定此命令含义的资源。

In general, variables can be modified with # , which removes a leading string. 通常,可以使用#修改变量,这会删除前导字符串。 If a is a variable with content foobar , then ${a#foo} strips the foo and evaluates to bar . 如果a是一个含有foobar内容的变量,那么${a#foo}删除foo并计算为bar In your case, $1 is a positional parameter, and ${1#/usr/newconfig} is the value of that string with "/usr/newconfig" removed from the start. 在您的情况下,$ 1是位置参数, ${1#/usr/newconfig}是从开头删除“/ usr / newconfig”的字符串的值。 If it does not match, the expression evaluates to the same string as $1. 如果它不匹配,则表达式求值为与$ 1相同的字符串。

However, this script has a rather significant issue in that it assigns cpfile in the environment of the ls that is run, but ls does not receive it as an argument. 但是,这个脚本有一个相当重要的问题,它在运行的ls的环境中分配cpfile,但是ls不接收它作为参数。 As a result, ls is going to operate on the current working directory rather than the directory passed as an argument to the script. 结果, ls将在当前工作目录上运行,而不是在作为参数传递给脚本的目录上运行。 (unless cpfile is assigned previously in the script somewhere.) (除非先前在某个地方的脚本中分配了cpfile 。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM