English 中文(简体)
• 如何把手脚文件中的班子指挥作为变数的价值?
原标题:how to import linux command in shell script file as the value of a variable ?

I am using Fedora 10. If I write java -version in terminal, it gives me java version. I want to write a shell script file to check whether the java version is greater than 1.5. The main problem is that I donot know how to assign the value of java -version command as to a variable of shell script. How to create shell script file for that ?

最佳回答

背书:

JAVA_VERSION=`java-version`
问题回答

如上文所述,您可使用背书,或(如果您的顶板有的话)使用以下格式:

你们应该直截了当,不停。

$ var=$(java -version 2>&1)
$ set -- $var
$ echo $3
"1.6.0_0"
$ echo ${3//[._"]/}
1600

现在,你可以比较每美元,看看其是否超过1,500美元。

上述所有答复都将为你们工作。 下面是你可用来获取变数价值的共同例子:

JAVA_VERSION=`java-version` or JAVA_VERSION="java-version" or JAVA_VERSION=$(command)

如何确定变量的价值是多种多样的。 你可以最容易地满足你的要求。 和Im

var=$(awk -F "   /^variable=/ {print $2}  script1.sh )
echo $var




相关问题
KornShell- Creating a fixed width text file

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 ...

unix find command

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 ...

encoding of file shell script

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

Case insensitive comparison of strings in shell script

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?

1. 露台式照像

在Windows XP中,没有一时出现指挥时,是否有办法操作一种灰色文字? 我常常需要把“善待”(工作)与“灰色”同起来,即使我的文字没有产出,......

热门标签