Results 1 to 4 of 4
I am having a problem scripting in ksh. I want to have a general subroutine which can query the version of a program. Since there are so many different ways ...
- 07-16-2009 #1Just Joined!
- Join Date
- Jul 2009
- Posts
- 2
ksh scripting problem
I am having a problem scripting in ksh. I want to have a general subroutine which can query the version of a program. Since there are so many different ways of querying an application, I want to have the actual command passed as a string, and then used as part of a command.
I have a subroutine which has
$4 = pathname terminated with /
$5 = binary name
$6 = cmd string
I can't figure out why the pipes and cuts don't work when I try and use a variable.Code:Get_Version () { # does not work QUERY="`$4$5 $6`" # works QUERY1="`$4$5 -version | cut -f1 -d, | cut -f3 -d' '`" echo "${QUERY} does not equal ${QUERY1}. Why not?" } FX_CMD="-version | cut -f1 -d, | cut -f3 -d' '" FX_PATH="/opt/sfw/lib/firefox" FX_BIN="firefox-bin" # nulls for example only Get_Version null null null $FX_PATH $FX_BIN "$FX_CMD"
perplexed <at> paiged <dot> fea <dot> st
- 07-17-2009 #2Linux Newbie
- Join Date
- Mar 2009
- Posts
- 228
First, some utilities display the version on stderr and pipe only pipes stdout. So you have to redirect stderr to stdout (2>&1).
Second, if you're going to pass the command as a parameter use the eval command to execute it.
You also forgot the trailing '/' on FX_PATH.
Code:Get_Version () { # does not work QUERY="`eval $4$5 $6`" # works QUERY1="`$4$5 -version 2>&1 | cut -f1 -d, | cut -f3 -d' '`" echo "${QUERY} does not equal ${QUERY1}. Why not?" } FX_CMD="-version 2>&1 | cut -f1 -d, | cut -f3 -d' '" FX_PATH="/opt/sfw/lib/firefox/" FX_BIN="firefox-bin" # nulls for example only Get_Version null null null $FX_PATH $FX_BIN "$FX_CMD"
- 07-17-2009 #3Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
You might find the ksh (and bash) builtin command command to be useful. See the man page for each for details.
If you are intending to use your function to display the version of system programs, note that many (but not all) of the GNU programs use "--version" (2 minus signs) to elicit the version of the program.
Good luck ... cheers, drlWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 07-17-2009 #4Just Joined!
- Join Date
- Jul 2009
- Posts
- 2
Thanks
drl, the inconsistencies between --version and -version (or even -V) is the reason for placing the command string into a variable. I can then make the subroutine generic, generally (without) concern about how to retrieve the version information.
lomcevak, I'll try your suggestions, and see if they help.


Reply With Quote