Jump to content

Bash script problems with strings [solved]


Recommended Posts

Hi folks,

 

after several years without practice (and being quite a newbie with Linux in particular) I'm trying to create some useful shell script. It is a very early version yet. The aim is to split a given text file into numbered blocks ready to pass on as SMS to mobiles. I've never gotten below line 27 within the script during execution (sometimes halfway working with minor changes, but writing to stdout instead of using the given variable), and the bloody thing hits me at last with the following error:

 

"../smsformat.sh: line 27: strcat: command not found"

 

Please see below:

 

! /bin/bash
# Purpose: Format given text from file to subsequent blocks ready for SMS sending
# Usage: smsformat -i <infile> -l <smslength> -o <outfile>
# or smsformat --help for short help

help()
{
 echo "Usage $0 -i <infile> -l <length> -o <outfile>"
}

if [ $# -lt 1 ]; then
 help
fi

while getopts i:l:o opt
do
  INTEXT=""
  case "$opt" in
 i) INFILE=$OPTARG
if [ -f $INFILE ] && [ -s $INFILE ]
then
	cat $INFILE | while read line
	do
	  INLINE=$line
	  INTEXT=eval strcat $INTEXT $INLINE
		done
	fi;;
 l) if [ $OPTARG -gt 0 ]
  then LEN=$OPTARG
	fi;;
 o) OUTFILE=$OPTARG;;
 *) help;;
  esac
done

echo Tracepoint
echo $INTEXT
HELPTEXT1='eval tr -s '\n' $INTEXT'
HELPTEXT2='eval tr -s '\r' $HELPTEXT1'
HELPTEXT3='eval tr -s '\n' '[:space:]' $HELPTEXT2'
# echo $HELPTEXT3
exit 0

 

Requesting your skilled comments,

 

scoonma

Edited by scoonma
Link to comment
Share on other sites

You've already seen the error message "strcat: command not found" - that's because strcat is a C function, not a bash function.

Instead of

		  INTEXT=eval strcat $INTEXT $INLINE

just do a simple concatenation:

		  INTEXT=$INTEXT$INLINE

Personally I'd keep the file reading stuff out of that while loop to make it clearer, but I guess it doesn't matter.

By the way, you have seen the "split" function, haven't you (man split) - doesn't that do what you want?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...