LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   simple bash script errors (https://www.linuxquestions.org/questions/linux-newbie-8/simple-bash-script-errors-773220/)

cbtsig215 12-03-2009 10:09 AM

simple bash script errors
 
Hi guys. I'm looking for a bit of help with a simple bash script I'm trying to create. From what I know about bash scripting (which is not much) it should work but doesn't. I'm using the latest release of ubuntu, but bash is bash... the distro shouldn't matter... i thought. Here's what I've got in the script.
_________________________________________________
echo Which file would you like to use?
read file
echo

echo What is the plugin ID you would like to process?
read ID
echo

echo Please wait.

cat $file | grep "|$ID|" | cut -d "|" -f3 | sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 | uniq > $ID.tmp
cat $ID.tmp | tr "\n" "," > $ID.txt

echo Cleaning temp files.

rm $ID.tmp

echo $ID Finished.
__________________________________________________

It seems to have issues with the "read file" line and tells me that it's not a valid identifier. After that it says that echo is a command not found.

Hopefully I've included enough info for someone to give suggestions.

Thanks in advance.

mk27 12-03-2009 10:25 AM

Quote:

Originally Posted by cbtsig215 (Post 3778516)
I'm using the latest release of ubuntu, but bash is bash... the distro shouldn't matter...

No, in fact it could not matter. As you say, bash is bash.

This script actually worked for me, altho I replaced the two cat lines with:

Code:

cat $file | grep "$ID"
Are you sure you are using exactly what you posted?

chrism01 12-03-2009 05:25 PM

It'd be easier if you post the exact error msgs ie run the prog and paste the invoking and all the msgs that appear.
Also, as above, post the exact code you are using.

catkin 12-04-2009 01:32 AM

What happens if you add this as the first line of your script
Code:

#!/bin/bash

Kenhelm 12-04-2009 03:33 AM

Does the script contain some non-printing characters?
For example, if the script has been edited in a Microsoft editor it could have some carriage return characters in it.

This will display control characters in the script using the '^' notation
(carriage returns will be shown as ^M )
Code:

cat --show-nonprinting script


All times are GMT -5. The time now is 10:48 PM.