How can I store the result of an an expression into a variable?
echo "hello" > var1
Can I also do something like this?
var1.substring(10,15);
var1.replace('hello', '2');
var1.indexof('hello')
PS. I had tried Googling, but was not sucessful.
As @larsmans comments, Konsole is the terminal emulator, which in turn runs a shell.
On linux, this is typically bash, but it could be something else.
Find out what shell you're using, and print the man page.
echo $SHELL # shows the full path to the shell
man ${SHELL##*/} # use the rightmost part (typically bash, in linux)
For a general introduction, use the wikipedia entry on the unix shell or the GNU Bash refererence
Some specific answers:
var1="hello"
echo ${var1:0:4} # prints "hell"
echo ${var1/hello/2} # prints "2" -- replace "hello" with "2"
And at the risk of showing off:
index_of() { (t=${1%%$2*} && echo ${#t}); } # define function index_of
index_of "I say hello" hello
6
But this goes beyond simple shell programming.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With