Tiny Core Linux
General TC => Programming & Scripting - Unofficial => Topic started by: fangis on March 23, 2014, 08:55:42 PM
-
Hello friends,
I have searched the documentation but can't seem to make this work.
What I want to do is the following:
get the user to type a word
convert the spaces in this word to commas, and save it into a new variable
but when i use:
read var
i dont know how to make sed modify this var. Is it possible?
Thanks for the help, i appreciate it.
-
var=`echo $var | sed 's: :,:g'`
Does that do what you need?
-
hi, thanks for the help.
No luck yet, i made the following script:
#!/bin/sh
echo "please type the string:"
read var
var=echo $var | sed 's::,:g'
echo "your converted string: $var"
this way gave no results, i typed, this is a test, gives:
line 5:this: not found
your converted string: this is a test
I also tried to use commas around echo, but it seems to not work
can you try the script?
thank you!
fangis
-
Hi fangis
You left out the back ticks usally found on the ~ key.
Try changing this:
var=echo $var | sed 's::,:g'
To this:
var=`echo $var | sed 's: :,:g'`
-
Or using tr:
var=`echo $VAR | tr " " ","`
or
var=$(echo $var | tr " " ",")
-
hey, thanks for the replies. It has worked! And I also did not know about this tr command so i will have a look. take care everyone.