PDA

View Full Version : [SOLVED] [Bash] Don't understand error in script!



JupiterV2
June 13th, 2008, 05:59 PM
I get the following error with the code below:

Error:

./cd_app.sh: 1: Bad substitution
cut: you must specify a list of bytes, characters, or fields
Try `cut --help' for more information.


Error with debug flags:

+ [ 3 /tmp/cdb.7505 = 0 ]
+ echo
+ echo metallica :−
+ echo
+ cut −f 2− −d , /tmp/cdb.7505
./cd_app.sh: 1: Bad substitution
cut: you must specify a list of bytes, characters, or fields
Try `cut --help' for more information.
+ echo
+ set +vxu


Full function:


list_tracks() {
if [ "$cdcatnum" = "" ]; then
echo "no CD selected yet"
return
else
grep "^${cdcatnum}," $tracks_file > $temp_file
num_tracks=$(wc -l $temp_file)
set -vxu
if [ "$num_tracks" = "0" ]; then
echo "no tracks found for $cdtitle"
else {
echo
echo "$cdtitle :−"
echo
cut -f 2- -d , $temp_file
echo
} | ${PAGER:−more}
set +vxu
fi
fi
get_return
return
}

What I don't understand is why the code "cut -f 2- -d , $temp_file" works on the command line as intended but not from within the script! What am I doing wrong?

KingTermite
June 13th, 2008, 06:12 PM
do you need quotes around the command?

ghostdog74
June 14th, 2008, 01:26 AM
use awk


awk -F"," '{print $2}' /tmp/dfdfs

geirha
June 14th, 2008, 02:53 PM
} | ${PAGER:−more}



It took me a while to figure out what this was doing. ${var:&# was unfamiliar to me. But then I realized it was an html-entity, and it was supposed to be ${PAGER:-more}. I doubt bash will understand the '−' symbol you are using, so change it to a regular '-'. It would be odd if that produced the error message you got though.

Martin Witte
June 14th, 2008, 08:54 PM
martin@toshibap200:~$ echo 1,2,3| cut -d, -f2
2
martin@toshibap200:~$ echo 1,2,3|cut -f 2- -d ,
2,3
martin@toshibap200:~$

JupiterV2
June 16th, 2008, 05:02 AM
So weird...I guess something wacky went on when I was putting in the 'dashes' as geirha suggested. I retyped them and it works perfectly! Thanks!