LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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-01-2005, 08:15 AM   #1
twintornado
LQ Newbie
 
Registered: Jun 2005
Location: Manchester, UK
Distribution: Mandrake 10.1
Posts: 4

Rep: Reputation: 0
Bash Script; command not found


Im having a problem assigning a resultant string of 3 piped commands to a variable.
The script is written in bash running on Mandrake 10.1.

The offending line is;
ALTCOURSE= `head -$LINE ./data | tail -1 | cut -d: -f1`

which is giving the error
./dupeswebct.sh: line 11: sm1024: command not found

as this works; echo `head -$LINE ./data | tail -1 | cut -d: -f1`
im guessing its the assignment to ALTCOURSE which is the problem.

The full script is;
#!/bin/bash
sed 's/-//g' ./webct.csv > ./webct2.csv

((TOTAL = `wc -l ./data | cut -f1 -d' '`))

echo $TOTAL
for ((LINE=1; LINE<=TOTAL; LINE++))
do
echo $LINE
#echo $(head -$LINE ./data | tail -1 | cut -d: -f1)
ALTCOURSE= `head -$LINE ./data | tail -1 | cut -d: -f1`
COURSE= `head -$LINE ./data | tail -1 | cut -d: -f2`
echo $ALTCOURSE $COURSE
sed -e "s/'$ALTCOURSE'/'$COURSE'/g" ./webct2.csv > ./webct3.csv
done

I guess there may be an alternative method as the head tail method seems a bit clumsy at best.

Thanks for your help
Cheers
 
Old 06-01-2005, 08:27 AM   #2
trevelluk
Member
 
Registered: Nov 2003
Location: Bristol, UK
Distribution: Debian Lenny, Gentoo (at work)
Posts: 388

Rep: Reputation: 32
The problem is the space between the = and the command. Change the line to ALTCOURSE=`head ....

What's happened is that bash interprets the space as a delimiter, and is setting ALTCOURSE to nothing, running the command specified in the backticks and then attempting to run the resulting value as a program. By removing the space, the value will be stored in ALTCOURSE as expected.

You'll also need to change the other lines where you've got spaces around the = sign.

As a quick side point, please use the code tags when you post code. It preserves the indentation and generally makes the post easier to read.
 
Old 06-01-2005, 09:59 AM   #3
twintornado
LQ Newbie
 
Registered: Jun 2005
Location: Manchester, UK
Distribution: Mandrake 10.1
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks for help.
The other '=' works because of the (()) notation which I tried with ALTCOURSE but with no luck.
Ill use the code button in future as well thanks for the tip
 
  


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
bash: command not found hamish Linux - Newbie 7 02-23-2011 04:28 PM
bash: g++: command not found m_lp_ql_m Linux - Software 8 07-08-2010 01:45 PM
bash -command not found- ALInux Linux - Newbie 3 12-30-2006 12:41 PM
bash: pg: command not found Chomper Programming 2 02-05-2005 02:22 AM
-bash: ls: command not found jchun Linux - General 3 11-02-2004 10:11 AM

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

All times are GMT -5. The time now is 11:03 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