Tiny Core Linux
Tiny Core Base => Raspberry Pi => Topic started by: jnovacek on May 20, 2016, 04:40:25 PM
-
how to split a string in bash?
IFS=', ' read -r -a array <<< "$string"
does not work
thanks
-
This question has nothing to do with RPi nor TC. Please use generic support forums and Google. First hit in Google search is
http://stackoverflow.com/questions/918886/how-do-i-split-a-string-on-a-delimiter-in-bash
Once again. Use this forum for TC specific questions only.
THANKS!
-
in other distributions it works, it does not work on Raspberry PI (Tiny Core Linux 7.0),
I get the message "syntax error: unexpected redirection"
-
Are you using bash?
-
Standard LInux stuff, grep, sed, awk, these can be used in shell scripts.
All available in busybox on piCore.
Extremely powerful and highly obscure languages and commands 8)
I use them to split out variables in config files and for data sorting.
One line of shell script with these in it can do the same as 100s of lines of python.
If you want to get really fancy then Perl, PHP.
-
in other distributions it works, it does not work on Raspberry PI (Tiny Core Linux 7.0),
I get the message "syntax error: unexpected redirection"
Your original question was different. Ask what you really want to know :(
-
One line of shell script with these in it can do the same as 100s of lines of python.
Only if you can't use Python. Back to the split, in Python it just a simple string method
split(';')
-
Are you using bash?
Good question. TC (piCore) is using BusyBox shell ash. If you want to work with Bash, install bash.tcz from repo and explicitely start it.
-
I used the "awk"
for my case it's ideal
val1=$(echo "$NAME" | awk -F':' '{print $1}')
val2=$(echo "$NAME" | awk -F':' '{print $2}')
thank you all