LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 06-27-2015, 11:16 PM   #1
jb60606
LQ Newbie
 
Registered: Jul 2012
Posts: 4

Rep: Reputation: Disabled
Shell script help?


This is a crude script I wrote in an application called CodeRunner, on Mac OS X. It works flawlessly when I run it within CodeRunner's built-in execution environment, but just sits there - presumably in a loop - anywhere else (ie: within Mac OS's own terminal or in a bash terminal on a RedHat Enterprise Linux system I have at work).

It takes arguments from the user and searches for them in a CSV file. When found in the file, it returns the rest of the line (where those args were found) to form a command structure used in another application.

I'm not exactly new to shell scripting, but seldom do it. Does anyone have any ideas as to what's wrong here?

Thanks

test.sh:

Code:
#!/bin/bash

read $1 $2 $3 $4

# This reads the CSV file, splitting each line. 
while IFS=',' read WHERE FEED TYP TRANSPORT SRC
do
	if [[ "$1" == "$WHERE" || "$1" == "$WHERE" ]] && [[ "$2" == "$FEED" && "$3" == "$TYP" ]]
	then
	mlisten="./mamalistenc -tport $TRANSPORT -S $SRC -s $4 -m lbm -dict_tport dict_prod\n"
	break
	elif [[ "$1" == "$WHERE" && "$2" == "$FEED" && "$3" == "$TYP" ]]
	then
	mlisten="./mamalistenc -S $SRC -s $4 -tport $TRANSPORT -m lbm -dict_tport dict\n"
	break
	else mlisten="Feed or Type wasn't found in the database\n"
	fi
done < transports.txt

echo -e "$mlisten"

transports.txt

CHI,ASX,MT,ctf_asx1_tport,CTF_ASX_CHI1
CHI,ASX,DB,ctf_asx1_db_tport,CTF_ASX_CHI1_DB
HOU,ASX,MT,ctf_asx1_tport,CTF_ASX_PROD1_HOU1
HOU,ASX,DB,ctf_asx1_db_tport,CTF_ASX_PROD1_HOU1_DB
LON,ASX,MT,ctf_asx1_QA_tport,CTF_ASX_LON11
LON,ASX,DB,ctf_asx1_db_QA_tport,CTF_ASX_LON1_DB

USAGE:

./scipt.sh <WHERE> <FEED> <TYPE> <SYMBOL>
e.g. ./script.sh LON ASX MT MY_SYMBOL


A successful run, using the command above, should display the following:

./mamalistenc -tport ctf_asx1_QA_tport -S CTF_ASX_LON11 -s MY_SYMBOL -m lbm -dict_tport dict_prod
 
Old 06-28-2015, 12:43 AM   #2
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
I prefer
If $* -eq 5 then
WHERE=$1
FEED=$2
TYP=$3
TRANSPORT=$4
SRC=$5
else
WHERE=$1
FEED=$2
TYP=$3
TRANSPORT=$4
fi

while ...

and so on.

Last edited by AnanthaP; 06-28-2015 at 12:47 AM.
 
1 members found this post helpful.
Old 06-28-2015, 01:12 AM   #3
jb60606
LQ Newbie
 
Registered: Jul 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by AnanthaP View Post
I prefer
If $* -eq 5 then
WHERE=$1
FEED=$2
TYP=$3
TRANSPORT=$4
SRC=$5
else
WHERE=$1
FEED=$2
TYP=$3
TRANSPORT=$4
fi

while ...

and so on.
That did it! Thanks - I was going nuts. Still kind of blows me away that it worked in the CodeRunner app. Guess it's back to a simple text/code editor and working directly in the shell.

thanks again.
 
Old 06-28-2015, 01:25 AM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by AnanthaP View Post
If $* -eq 5 then
I think you meant
Code:
if [ $# -eq 5 ]; then
 
Old 06-28-2015, 05:20 AM   #5
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
Quote:
if [ $# -eq 5 ]; then
Yes Of course.

Clearly winrunner, coderunner etc serve to add a level of complication and absolve testers from tessting in the actual environment.

OK
 
  


Reply



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
Shell script for run an shell script on server using ssh bloodstreetboy Linux - Server 5 01-12-2013 03:23 AM
How to pass command line arguments from one shell script to another shell script VijayaRaghavanLakshman Linux - Newbie 5 01-20-2012 09:12 PM
Executing a Shell script with 654 permissions inside another shell script. changusee2k Linux - Newbie 2 06-07-2011 07:58 PM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:32 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration