LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-30-2003, 11:22 AM   #1
cosiek
LQ Newbie
 
Registered: Aug 2003
Location: Poland
Distribution: COLD Linux
Posts: 28

Rep: Reputation: 15
Read contents of file and execute command


I have a file named PKGSEL with on line like this:

"Var1" "Var2" "Var3" "Var4"

I don't know how to do something like this: if PKGSEL file contains "Var1" then the script should execute a command, if it contains "Var2" is should execute another command - and so on...
 
Old 09-30-2003, 11:39 AM   #2
mfeat
Member
 
Registered: Aug 2003
Location: Akron, OH
Distribution: Fedora Core 3
Posts: 185

Rep: Reputation: 30
VAR=`cat PKGSEL`
if [ "$VAR" = "Var1" ];
 
Old 09-30-2003, 11:41 AM   #3
mfeat
Member
 
Registered: Aug 2003
Location: Akron, OH
Distribution: Fedora Core 3
Posts: 185

Rep: Reputation: 30
VAR=`cat PKGSEL`
if [ "$VAR" = "Var1" ]; then
command1
elif [ "$VAR" = "Var2" ]; then
command2
elif [ "$VAR" = "Var3" ]; then
command3
fi
 
Old 09-30-2003, 12:07 PM   #4
mfeat
Member
 
Registered: Aug 2003
Location: Akron, OH
Distribution: Fedora Core 3
Posts: 185

Rep: Reputation: 30
If there's more than one "Var" on the line in the file this will work, also if the quotes are actually in the file this handles it:

do_cmd()
(
if [ "$1" = "Var1" ]; then
echo command1
elif [ "$1" = "Var2" ]; then
echo command2
elif [ "$1" = "Var3" ]; then
echo command3
fi
)
list_vars()
{
pcount=$#
i=1
while [ $i -le $pcount ]; do
do_cmd $1
shift
(( i = i + 1 ))
done
}
list_vars `cat PKGSEL | sed 's/"//g'`
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to read contents of CPU registers? irfanhab Programming 1 12-28-2004 09:04 AM
execute php file on command prompt robberttheman Linux - Newbie 0 09-23-2004 02:24 PM
execute shell command inside of tcl file khucinx Programming 1 07-05-2004 02:29 PM
tar command : error: file changed as we read it sneezesnoeze Linux - General 2 04-05-2004 07:56 PM
How to read and change the contents of a text file? Bassam Linux - General 11 02-26-2004 05:08 AM


All times are GMT -5. The time now is 03:48 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration