Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

new question...new thread...scripting!

Status
Not open for further replies.

Igaduma

Technical User
Nov 23, 2001
322
BE
Hi all,

Suppose I have inside a script following variable:

"a a a"

It needs to be changed into "a+a+a".
Changing the space characters into the + character.

The reason for this is that it has to be part of an URL, which cannot have any spaces.

It must be straightforward...but got no clue.


Thanks for the help!



 
Something like:

new_variable=echo "a a a" | tr -s ' ' '+'

where you substitute "a a a" with your variable name will do the trick, but there are no doubt simpler sed/awk solutions.
 
Hi KenCunningham!

Your trick did it, but only when echo'ing it out
can't get it to dump it into the new variable.

Must be, again, a bracket-thing!

This is what I got so far:

#!/bin/ksh
#Geek-stuff: Get your server to mail you sms!
part2=0032486506968 #target mobile number
part3=172311141 #server source IP adress
part4=$(/usr/bin/uptime) #get server uptime

part5=echo $part4 | tr -s ' ' '+'

#dump it into the string

full='xxxx.xxx.xx/cgi-bin/SendSMSMessage.pl?dest_number='$part2'&source_number='$part3'&message_text='$part4'&notification=0'

echo $part5

# use curl to fire string off to SMS-C server and wait for mobile to beep!
#/opt/bin/curl $full

When echoing $part5 it is empty!

 
got it working!

part5=$(echo $part4 | tr -s ' ' '+')

is the syntax to use.

Thanks all for the help...

My girlfriend will go insane when I get messages on my mobile about server-stats....


 
You were quite correct with the 'bracket thing' then! Hmm - the girlfriend thing could be a more difficult proposition! Good luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top