Jump to content
scoonma

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

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

Ah, thanks neddie, I've spent hours looking for some explicit concatenation "function". Didn't know it was that simple. :wall::thumbs:

I'll also go on with split. Great!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...