这句shell命令该怎么解释?
$echo 2 * 3 > 5 is a number.这句shell命令得出的结果应该是什么? 当前目录下一个名字为5的新文件,它包含字符串2,当前目录下所有文件的名称,接下来是什么呢,想了一天,脑子还是没有转过来,哪位兄弟来帮帮忙 :cry: 我的理解是:
首先,“*”的意思是匹配当前目录下所有的文件名(包括目录名)。
其次,把echo的输出重定向到名为“5”的文件。
最后,echo的输出是 -- 2 当前目录的文件名列表 3 is a number。 最好加引号~
3 is a number。
你的意思所有的输出都是进入5这个文件的是吧, 我也知道这个结果,但是我对最后的 "3 is a number"有点疑问, 它怎么也会出现在这个文件中的? :? 我想这跟没有加引号有关吧。
Re: 这句shell命令该怎么解释?
$echo 2 * 3 > 5 is a number.这句shell命令得出的结果应该是什么? 当前目录下一个名字为5的新文件,它包含字符串2,当前目录下所有文件的名称,接下来是什么呢,想了一天,脑子还是没有转过来,哪位兄弟来帮帮忙 :cry:
等价于:
echo 2 * 3 is a number. > 5
简单地说,因为重定向管道“>”只认识一个参数,所以除了“> 5” 被单独处理外,其他所有一切都是 echo 的参数。
简单地说,因为重定向管道“>”只认识一个参数,所以除了“> 5” 被单独处理外,其他所有一切都是 echo 的参数。
:-D 都是高手啊 请帮忙看一下下面的SHELL 脚本(mytar.sh)有什么问题:
#!/bin/bash
if ["$1##*."="tar"]
then
echo "this is a tarball".
else
echo"this is not a tarball"。
fi
在命令行输入/root/mytar.shfile.tar时总是提示
line2: command not found
l第三行的`THEN`是多余的.
以上是在RH9上做的.
linky_fan 写到:
$echo 2 * 3 > 5 is a number.
这句shell命令得出的结果应该是什么? 当前目录下一个名字为5的新文件,它包含字符串2,当前目录下所有文件的名称,接下来是什么呢,想了一天,脑子还是没有转过来,哪位兄弟来帮帮忙 Crying or Very sad
等价于:
echo 2 * 3 is a number. > 5
简单地说,因为重定向管道“>”只认识一个参数,所以除了“> 5” 被单独处理外,其他所有一切都是 echo 的参数。
_________________
最近在看orelly的bash书, 这是上面的一个例子, 后来又看了一遍, 注意到了其中的一句解释, ">"这类的重定向苻放在shell命令的任何位置都是可以的, 效果一样....", 呵呵,恍然大悟. :mrgreen:
#!/bin/bash
if ["$1##*."="tar"]
then
echo "this is a tarball".
else
echo "this is not a tarball"。
fi
看个后缀名就可以了吧 :neutral: echo `expr 2 \* 3 \> 5`
引用:
#!/bin/bash
if ["$1##*."="tar"]
then
echo "this is a tarball".
else
echo "this is not a tarball"。
fi
看个后缀名就可以了吧 Neutral
下面不是更好?
#!/bin/bash
if [ ! -z "`file $1 | grep bzip2`" ]; then
echo "bunzip2"
elif [ ! -z "`file $1 | grep gzip`" ]; then
echo "gunzip"
elif [ ! -z "`file $1 | grep Zip`" ]; then
echo "unzip"
#
#add other file type
#
else
echo "other"
fi
请帮忙看一下下面的SHELL 脚本(mytar.sh)有什么问题:
#!/bin/bash
if ["$1##*."="tar"]
then
echo "this is a tarball".
else
echo"this is not a tarball"。
fi
在命令行输入/root/mytar.shfile.tar时总是提示
line2: command not found
l第三行的`THEN`是多余的.
以上是在RH9上做的.
[]内各项要有至少一个空格,即
[ "$1##*." = "tar" ]
正确的判断应该用file,
file $1|grep -q "tar archive"&&echo $1 "is a tarball file"||echo $1 "is not a tarball file"
页:
[1]