Linux Lite Forums

Development => Scripting and Bash => Topic started by: Vera on June 13, 2018, 10:00:00 AM

Title: What shell do YOU use for scripting or command-line on LL?
Post by: Vera on June 13, 2018, 10:00:00 AM
Interested to see what shell people are using for their scripting and/or command-line purposes. Thanks!
Title: Re: What shell do YOU use for scripting or command-line on LL?
Post by: bitsnpcs on September 12, 2018, 04:38:24 PM
I am learning to use bash.
Title: Re: What shell do YOU use for scripting or command-line on LL?
Post by: kpanic on September 13, 2018, 06:06:12 PM
I am learning to use bash.

GZ man, and Vera too, of course!
Shell scripting is the most powerful tool to use. And a child can learn it (with the time they use in
all those 'social media' sites).

Ps.
To Vera: I begin the scripts with
#!/bin/bash
# explicitely, because bash is the best shell but it is not the default shell in LL
Title: Re: What shell do YOU use for scripting or command-line on LL?
Post by: bitsnpcs on September 13, 2018, 07:07:01 PM
I am learning to use bash.

GZ woman, and Vera too, of course!
Shell scripting is the most powerful tool to use. And a child can learn it (with the time they use in
all those 'social media' sites).

Ps.
To Vera: I begin the scripts with
#!/bin/bash
# explicitely, because bash is the best shell but it is not the default shell in LL

Title: Re: What shell do YOU use for scripting or command-line on LL?
Post by: bitsnpcs on September 14, 2018, 07:15:46 AM
There is some scripting at the end of the Linux Command Line book I use, I am not anywhere near the end yet, as I learn slowly and stop start when disrupted for long periods at a time.
I also learn from Linux Bible, need to fix virtualbox before can carry on with that. Just havent been motivated to do so yet.
After these books I have the one to start titled,  Linux Command Line and Shell Scripting Bible.
Hopefully in some future year when/if I manage to complete those I will have a basic foundation to progress from.

I use social sites such as this forum, and YouTube for music.

Is it like the shebang ?

Code: [Select]
#!/usr/bin/env python
I used in the first Python apps I made so they execute
Title: Re: What shell do YOU use for scripting or command-line on LL?
Post by: Moltke on September 14, 2018, 11:12:38 PM
Quote
explicitely, because bash is the best shell but it is not the default shell in LL
 
@kpanic
To stablish bash as your default shell you can use the cat and chsh commands. First, in your terminal type
Code: [Select]
$ cat /etc/shells

This will list all available/installed shells in your system, then use chsh to change to a different shell, say bash.
Code: [Select]
$ chsh -s /usr/bash

it will ask for your password, type it in, logout/login, open a terminal, type
Code: [Select]
$ echo $Shell and you should see the new shell's name displayed.


(http://i65.tinypic.com/20fqgrn.jpg)

(http://i64.tinypic.com/11sh4lf.jpg)

@bitsnpcs  there's a very good book you might find quite helpful; The Linux Shell Scripting Cookbook. You can grab it here: https://gutl.jovenclub.cu/wp-content/uploads/2013/10/Linux.Shell_.Scripting.Cookbook.pdf

Title: Re: What shell do YOU use for scripting or command-line on LL?
Post by: bitsnpcs on September 15, 2018, 03:15:17 AM
@bitsnpcs  there's a very good book you might find quite helpful; The Linux Shell Scripting Cookbook. You can grab it here: https://gutl.jovenclub.cu/wp-content/uploads/2013/10/Linux.Shell_.Scripting.Cookbook.pdf (https://gutl.jovenclub.cu/wp-content/uploads/2013/10/Linux.Shell_.Scripting.Cookbook.pdf)

@Moltke Thank You, I've grabbed it and will work through it :)
I have done the first example in book


(https://preview.ibb.co/erAfRe/Screenshot_2018_09_15_09_21_11.png)

I like it 8) do you want to make a thread for this book @Moltke ?
I had a play with the options at end of the section, and some trial/error spacing, I wasn't able to get Name  and Mark in to the centre of their color blocks yet, also had to copy/paste the name character as wasn't sure how to do it in terminal -

(https://preview.ibb.co/jEhuKz/Screenshot_2018_09_15_12_41_58.png)
Title: Re: What shell do YOU use for scripting or command-line on LL?
Post by: Moltke on September 15, 2018, 09:51:19 AM
Quote
I like it 8) do you want to make a thread for this book @Moltke?

@bitsnpcs  I'd love to! :) I've been reading it and trying some of the examples in the book, and it'll be really helpful to share ideas, doubts, experience, thoughts with someone else and thus improving the learning experience, so sure, let's make it happen! There's only one thing you should know; I might not be able to post an answer/reply as soon as I wish. I'm dealing with some problems with my wired connection and as a matter of fact I'm currently using a usb dongle and it's bandwith limited so the pc isn't online 24/7 but only when I want/need it to. Other than that I'd be more than happy to be patr of it!  ;D 

BTW, I just noticed there's a revisited third edition of the book published last year, the one you and I have is the second one. I don't know what the differences might be, if any though, but you can grab it here: https://coderprog.com/linux-shell-scripting-cookbook-3rd/

Also, I found this other one and it lloks quite interesting https://www.pdfdrive.com/pro-bash-programming-scripting-the-gnulinux-shell-e18888064.html
Title: Re: What shell do YOU use for scripting or command-line on LL?
Post by: bitsnpcs on September 15, 2018, 10:37:38 AM
@Moltke that will be great 8) , I understand about your connection at the moment.

Thank you for the links. :)
It appears the third version has lots of empty space, maybe missing images. Example in Second edition I am on page 32, this is spread out and up to page 106 in the third edition.

I'll work through the pro bash book too, it does look interesting as well.
Title: Re: What shell do YOU use for scripting or command-line on LL?
Post by: Moltke on September 16, 2018, 10:47:16 AM
Quote
It appears the third version has lots of empty space, maybe missing images

@bitsnpcs  yes, you're right. I noticed that too. Anyway, it doesn't seem to be too many changes from the second edition, so I guess we're good using that one.  ;D
I just found this https://bash.cyberciti.biz/guide/Main_Page it has several examples and explanatios are quite clear. I think it's a good resource for learning scripting and bash. Hope you like it. :)

cheers!
Title: Re: What shell do YOU use for scripting or command-line on LL?
Post by: bitsnpcs on September 16, 2018, 01:50:20 PM
Quote
It appears the third version has lots of empty space, maybe missing images

@bitsnpcs  yes, you're right. I noticed that too. Anyway, it doesn't seem to be too many changes from the second edition, so I guess we're good using that one.  ;D
I just found this https://bash.cyberciti.biz/guide/Main_Page (https://bash.cyberciti.biz/guide/Main_Page) it has several examples and explanatios are quite clear. I think it's a good resource for learning scripting and bash. Hope you like it. :)

cheers!

@Moltke  yes it will be good using the second edition.
Thank You for the link, I've saved it, I'll work through the current 2 books (second edition and pro bash) first it will be useful for the examples and explanations as you wrote :)
Title: Re: What shell do YOU use for scripting or command-line on LL?
Post by: Vera on September 16, 2018, 05:00:25 PM
Thanks for the helpful links about scripting, @Moltke .

I use the fish shell https://fishshell.com/ (https://fishshell.com/) for most of my stuff (I installed it via Synaptic). It's very user-friendly, and has good use of color.

On the command-line, if I type in something that looks syntactically wrong to the shell, it'll highlight it in red, which is helpful to me. It also displays autosuggest on command line without me needing to hit tab or whatever (just hit right arrow to accept autosuggestion, or carry on typing whatever I was typing if I don't want to accept autosuggestion).

I still have bash as my login user shell, but I switch to the fish shell for 99% of whatever I'm doing, including shell scripting. The fish shell just seems more intuitive to me, and the autosuggest feature on command line has definitely resulted in me getting things done a lot faster.
Title: Re: What shell do YOU use for scripting or command-line on LL?
Post by: Moltke on September 16, 2018, 10:22:07 PM
You're welcome @Vera

Quote
The fish shell just seems more intuitive to me, and the autosuggest feature on command line has definitely resulted in me getting things done a lot faster.

I also use fish for repetitive tasks since as you stated its auto-completion feature is most useful in those cases, so I don't have to type over and over the same commands. But I use bash as the default one. Truth is I don't do/know much scripting, I'm learning how to. :)

You're very welcome @bitsnpcs glad you found it useful.
Title: Re: What shell do YOU use for scripting or command-line on LL?
Post by: bitsnpcs on September 16, 2018, 10:24:56 PM
@Moltke can you add the links in to the threads for the 2 books please ? :)

Title: Re: What shell do YOU use for scripting or command-line on LL?
Post by: Moltke on September 16, 2018, 10:33:25 PM
Quote
@Moltke can you add the links in to the threads for the 2 books please ? :)

Sure, I will. :)
Title: Re: What shell do YOU use for scripting or command-line on LL?
Post by: kpanic on September 17, 2018, 12:31:05 PM
@Moltke ,

Thank you for the information!
chsh changes the login shell, I would leave that as it is though, since it is part of the OS.

I suggest that people won't touch the system-wide settings like this. It is so much safer to
just invoke #!/bin/bash to the user scripts instead of the usual #!/bin/sh (which points to dash shell in LL).
Title: Re: What shell do YOU use for scripting or command-line on LL?
Post by: Moltke on September 17, 2018, 03:31:36 PM
@kpanic it is completely safe to change your login shell and/or prompt to whatever else you want. No harm will be made. However, you can always make a backup of your .bashrc file before whatever change you plan to do and if for any reason you don't feel saisfied with the result or anything goes wrong, you can just replace the .bashrc and get everyhing back to its default. 

hope this helps! :)

Title: Re: What shell do YOU use for scripting or command-line on LL?
Post by: kpanic on September 17, 2018, 05:00:55 PM
@kpanic it is completely safe to change your login shell and/or prompt to whatever else you want. No harm will be made. However, you can always make a backup of your .bashrc file before whatever change you plan to do and if for any reason you don't feel saisfied with the result or anything goes wrong, you can just replace the .bashrc and get everyhing back to its default. 

hope this helps! :)


@Moltke ,

If it is completely safe, please post this idea with a "HELPFUL TIP" tag on it - after all, you make the claim that
it is completely safe and no harm will be made.
Why should I make any backups if it's completely safe? Should it read then: "not so completely safe" ?

I'm not making any changes, I use #!/bin/bash in my bash scripts, instead of the usual #!/bin/sh -
because /bin/sh points to dash shell.

Title: Re: What shell do YOU use for scripting or command-line on LL?
Post by: Moltke on September 17, 2018, 06:10:26 PM
Quote
If it is completely safe, please post this idea with a "HELPFUL TIP" tag on it - after all, you make the claim that
it is completely safe and no harm will be made.
Why should I make any backups if it's completely safe? Should it read then: "not so completely safe" ?

Indeed. That's how smart Linux is  ;D otherwise those kind of files like .bashrc wouldn't be in your home folder where you can manipulate them at will and you'd need to become root in order to make any changes on them. It is completely safe to do so, I only suggested that in the event that you wished/were to change your shell login and /or prompt, you could make a backup of the the original .bashrc file, just for the sake of it, but it's really not neccesary.

Quote
I'm not making any changes, I use #!/bin/bash in my bash scripts, instead of the usual #!/bin/sh -
because /bin/sh points to dash shell.


I never said you should/have to change anything, that's entirely up to you. If you're happy with your config keep it that way no matter what anyone else may say. I use bash, fish, dash, zsh and switch back from one to the other and haven't had any problems whatsoever.  Like I said, it's entirely up to you and nobody else.

This is the contents of my .bashrc:

#
# ~/.bashrc
#

# If not running interactively, don't do anything
[[ $- != *i* ]] && return

alias ls='ls --color=auto'
PS1='[\u@\h \W]\$ '
EDITOR=/usr/bin/nano
# You may uncomment the following lines if you want `ls' to be colorized:
eval "`dircolors -b ~/.dircolorsrc`"
export LS_OPTIONS='--color=auto'
export PS1='\[\e[1;36m\][\t \u \[\e[0m\]\W \$] '

# Correct dir spellings
shopt -q -s cdspell

# Make sure display get updated when terminal window get resized
shopt -q -s checkwinsize

# Turn on the extended pattern matching features
shopt -q -s extglob

# Append rather than overwrite history on exit
shopt -s histappend

# Make multi-line commandsline in history
shopt -q -s cmdhist

# Get immediate notification of background job termination
set -o notify

# Store 2000 commands in history buffer
export HISTSIZE=2000

# Store 2000 commands in history FILE
export HISTFILESIZE=2000     

# Avoid duplicates in hisotry
export HISTIGNORE='&:[ ]*'

And this is how my terminal looks like:

(http://i64.tinypic.com/t9uu8o.jpg)

Sorry if I bother you somehow, I didn't mean to do that, I simply shared something that it's posisible and completely, entirely safe to do, because like I said before, Linux is smart enough not to let you screw things up. :)

Cheers!
Title: Re: What shell do YOU use for scripting or command-line on LL?
Post by: kpanic on September 17, 2018, 06:54:32 PM
@Moltke ,

Did I ever say I want to change my login shell?
If so, would you point the place I did so, please?

And for your information, I don't take instructions from noobs,
I was in this business when you were ~5 years old

Why don't you go and post your chsh-idea to the 'HELPFUL TIP' area?
I answer for you: because it is not a helpful idea!

Do you get it?
Title: Re: What shell do YOU use for scripting or command-line on LL?
Post by: Moltke on September 17, 2018, 08:13:47 PM
Quote
Did I ever say I want to change my login shell?

I wrote: "if you wished/were to change", this is a conditional clause of an hipothetical situation meaning that something must happen that "you wished/were to" which you didn't/weren't to. I think you're the one who's confused but nevermind, I'm a noob  ;D

Quote
I was in this business when you were ~5 years old
good for you! I've been using Linux like for ten years only. First, dual booting with windows and for like 2 years now switched entirely to Linux and have never looked back and never will  8)

Quote
Why don't you go and post your chsh-idea to the 'HELPFUL TIP' area?
I answer for you: because it is not a helpful idea!

I've already created the post, have a look if you wish (and I'm not saying that you do, of course you don't!) it's not "my chsh idea", I didn't created it lol I wished! lol It's there and it is completely safe to use. https://www.linuxliteos.com/forums/tutorials-27/changing-loging-shell-andor-terminal-prompt/msg43197/?topicseen#msg43197

Quote
Do you get it?

Yes, I did. You have a serious problem and need to find some help real soon.

end of the conversation.
Title: Re: What shell do YOU use for scripting or command-line on LL?
Post by: Jerry on September 18, 2018, 06:14:30 AM
Completely unnecessary for this type of thread to get to this level of personal. I have better things to do getting 4.2 ready than to deal with completely unavoidable situations. List your information and keep it technical...it's that simple.
Title: Re: What shell do YOU use for scripting or command-line on LL?
Post by: Moltke on September 18, 2018, 08:01:49 PM
Completely unnecessary for this type of thread to get to this level of personal. I have better things to do getting 4.2 ready than to deal with completely unavoidable situations. List your information and keep it technical...it's that simple.

You're right @Jerry I'm really sorry. I didn't mean to cause any trouble and/or controversy. Won't happen again.
Title: Re: What shell do YOU use for scripting or command-line on LL?
Post by: kpanic on September 20, 2018, 09:37:16 PM
@Moltke  & @Jerry ,

Now I agree with Moltke.
I hate to cause any kind of polemic but at the same time I want to share
my opinion and sometimes these things collide.