如果在文本档案中没有显示扼杀物,我会试图控制一些炮弹。 如果给我一个错误的话,我会把这一界线推向指挥线。
if [ $(cat textfile.txt | grep "search string") -eq "" ]; then; echo "some string"; fi;
错误:
-bash: [: -eq: unary operator expected
如果在文本档案中没有显示扼杀物,我会试图控制一些炮弹。 如果给我一个错误的话,我会把这一界线推向指挥线。
if [ $(cat textfile.txt | grep "search string") -eq "" ]; then; echo "some string"; fi;
错误:
-bash: [: -eq: unary operator expected
如您使用<代码>[,以进行比较,则需要使用=
而不是-eq
。 你们也需要一些引言。
if [ "$(cat textfile.txt | grep search string )" = "" ]; then; echo "some string"; fi;
注:grep
可将档案名称作为理由,因此没有必要cat <>/code>。 也可直接使用<代码>grep
的回报价值: 如果找不到搜身区,则将可恢复1号。
if [ "$(grep search string textfile.txt)" ]; then
echo "some string";
fi
更紧凑的方式是使用逻辑和<代码>和 amp;&。
grep "search string" textfile.txt && echo "some string"
www.un.org/Depts/DGACM/index_french.htm 如果能够找到所要求的线路(如果不是的话,如果出现错误的话,则有2条),那么你就只能使用:
grep "search string" textfile.txt >/dev/null 2>&1
if [[ $? -ne 0 ]] ; then
echo Not found
fi
如果您
if [ "$(cat textfile.txt | grep search string )" == "" ] ; then
echo "It s not there!"
fi
grep -F -q -e search string textfile.txt || echo Not found
注:
-F
prevents the interpretation of the search string as a regular expression.-q
suppresses all output and returns immediately after the first instance was found, making the search much faster if the string occurs at the beginning of a large file.-e
specifies the pattern explicitly, allowing patterns that start with a dash.此处无需方括号。 由于<代码>[实际上是指挥,任何指挥均可在你使用时使用。 因此,我们可以在这里使用<代码>grep。 由于<代码>grep,无需使用<代码>cat。 而且,你们有两处太多的半殖民地。
if grep -q "search string" textfile.txt; then echo "some string"; fi
或
if grep "search string" textfile.txt > /dev/null 2>&1; then echo "some string"; fi
I need to create a simple fixed width text file in KornShell (ksh). My current attempt using printf to pad the string isn t working out very well. What s the shortest, cleanest way to create a fixed ...
how to use the find command to find files/directories which are not matching the pattern. for eg: find <some options > -name "dontfile.txt" should give me output of all the find whose file ...
I need to put the contents of all *.as files in some specified folder into one big file. How can I do it in Linux shell?
How can I check the file encoding in a shell script? I need to know if a file is encoded in utf-8 or iso-8859-1. Thanks
The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?
I like to write bash shell scripts on my iPhone, put them in an app folder with an icon, plist, etc., so they execute like apps by tapping their icon on SpringBoard. This is not interactive like ...
Whenever I start a shell in vim using :sh, it doesn t source my ~/.bashrc file. How can I get it to do this automatically?
在Windows XP中,没有一时出现指挥时,是否有办法操作一种灰色文字? 我常常需要把“善待”(工作)与“灰色”同起来,即使我的文字没有产出,......