Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What language runs after I start a Konsole window, and what can it do?

Tags:

linux

shell

  1. How can I store the result of an an expression into a variable?

    echo "hello" > var1
    
  2. 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.

like image 975
Mathew Kurian Avatar asked Jan 27 '26 18:01

Mathew Kurian


1 Answers

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.

like image 151
Henk Langeveld Avatar answered Jan 30 '26 10:01

Henk Langeveld



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!