Code works on local linxu box, but not on uni unix box?


Recommended Posts

hey guys I have done a script on my local linux box all seems to work fine but when i come to port it over to Unix it trows a fit and i do not know why can you enlighten me please?

heres the script

#!/bin/sh

for file
do	  case $file in
		[A-Za-z0-9]*\.\*) type=main
			   ;;
		\*\.[A-Za-z0-9]* )type=extension
			   ;;
		[A-Za-z0-9]*\.[A-Za-z0-9]*)type=all
			   ;;
		esac

done

endFile=$file
i=0


[b]while [ $i -ne $(($#-1)) ][/b]
do	  i=$(($i+1))
		eval files=\$$i

		case $type in
		'extension')	extension=`echo $endFile |sed -e 's/\*\./\./'`
						newfile=`echo $files |sed -e "s/\.[A-Za-z0-9]*/$extension/"`
						echo  "if $files had been renamed it would now be $newfile"
			   ;;
		'main')		 fileName=`echo $endFile | sed -e 's/\.\*//'`
						newFile=`echo $files | sed -e "s/[A-Za-z0-9]*\.\(.*[A-Za-z0-9]*\)/$fileName\.\1/"`
						echo "if $files had been renamed it would now be $newFile"
		#			   mv $files $newFile
			   ;;
		esac
done

the Bold bit is where it throws the problem say unexpected ( but yet it works in linux?

thanks matt

Link to comment
Share on other sites

try using ` and ` instead of $( and ). /bin/sh may be a symlink to bash on your linux box, and it could be a symlink elsewhere on your unix box. may not work, but hey you never know.

Link to comment
Share on other sites

right i tried what you said and it seems to have got just a tad further but i now get this error!

/homedir/ilex-s11/mdelough/bin/dosRename: 6: not found

/homedir/ilex-s11/mdelough/bin/dosRename: test: argument expected

6 is the number of attributes that have been supplied i think anyway, and i have narrowed the error to be this bit in bold

....................................
[b]while [ $i -ne `$# - 1` ] [/b]
do	i=+'1'

	eval files=\$$i

	case $type in
	'extension')	extension=`echo $endFile |sed -e 's/\*\./\./'`
			newfile=`echo $files |sed -e "s/\.[A-Za-z0-9]*/$extension/"` 
			echo  "if $files had been renamed it would now be $newfile"
	;;
	'main')		fileName=`echo $endFile | sed -e 's/\.\*//'`
			newFile=`echo $files | sed -e "s/[A-Za-z0-9]*\.\(.*[A-Za-z0-9]*\)/$fileName\.\1/"`
			echo "if $files had been renamed it would now be $newFile"
	#		mv $files $newFile
	;;
	esac
done

Link to comment
Share on other sites

sorry i took a quick glance at the code the first time and didnt realize you were just doing math. the reason it is throwing that error is because it is now trying to execute a program called 6 heh. do you have bash available? if so, try running your first script with #!/bin/bash at the top instead. if it doesnt work then you may have to store $# in a variable, then test against the $var - 1 as you did in your first script, rather than $# - 1.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.