DEV Community

Cover image for The Shell Introduction I Wish I Had

The Shell Introduction I Wish I Had

Max Antonucci on July 16, 2018

Hey there past me. Hope you're doing well and keeping the horrible regrets to a minimum. I'm here to help in that regard. At least with career-rela...
Collapse
 
rpalo profile image
Ryan Palo

This is awesome! I love reading different people's approaches to teaching something to a beginner. I like that you took the time to explain what a shell is and why it's useful, because I didn't get that when someone showed me a shell for the first time and I wish I would have.

A couple gotchas to add for newbies:

  • When you're setting variables, make sure you don't have spaces on either side of the equals sign. my_var="Soup" is right, but my_var = "Soup" will cause errors. The bash shell uses spaces to separate commands from their arguments and split strings into lists, so doing it the second way will make it think you're trying to run the my_var command with first argument "=" and second argument "Soup".
  • I've read a couple of things including the Bash manual that say that, in general, using aliases should be avoided in preference to using functions pretty much always. That being said, there's no Bash police, so do what works for you, especially if you're not sharing your scripts with anybody.

Anyways, great post! Thanks again :)

Collapse
 
maxwell_dev profile image
Max Antonucci

Thanks for the feedback! Good point about the variable names, this article is a pretty broad overview so its no surprise I missed a few details like that. But they, I can always write a few follow-up pieces too.

I agree about it being good to explain why the Shell matters. I think that's actually the most important detail for me, since in the start when I researched it, there's no shortage of guides about how to use it. But until I really understood the why with the Pragmatic Programmer, I never saw why it mattered so much to stick through the learning process and bring that all back to my career. That's likely the part of the article I'd have wanted the most for my past self haha.

Collapse
 
rpalo profile image
Ryan Palo

Yep, and I think you definitely did a great job at that!

Collapse
 
nobozo profile image
Jon Forrest

"Vim is, at its core, a text-editor. It's built into the Shell"

This isn't true (that Vim is built into the Shell). Vim might be in a directory contained in your PATH variable, but it's not built into the shell. (Note that I don't capitalize "shell", and I don't know why you do, but that's quibbling.)

Collapse
 
eljayadobe profile image
Eljay-Adobe

I'm a Unix nerd, through-and-through. I love the Mac. It's a great Unix system. I've heard it has a GUI too, but I stick with Terminal and bash. GUI is probably just a fad.

Collapse
 
vitalcog profile image
Chad Windham

GUI is just a fad. I laughed so hard when I read that! good job

Collapse
 
pmcgowan profile image
p-mcgowan

My fav -

cdl() { cd "$@" && ls ; }

It took me a very long time before I started using that, but 90% of the time I'm going to ls after a cd. And because I'm silly, I end up ls'ing twice pretty often...

Collapse
 
maxwell_dev profile image
Max Antonucci

That's true, I often do the same. May add this to my alias list myself.

Collapse
 
vlasales profile image
Vlastimil Pospichal
alias bashrc='vim "$HOME/.bashrc" && . "$HOME/.bashrc"'
alias ll='ls -l'
alias mv='mv -i'
alias header='curl -s -D-'
alias myIP='ip route get 8.8.8.8 | awk '\''{print $NF, "GW", $3; exit}'\'''
Collapse
 
lt0mm profile image
Tom

About vim, you can add

export EDITOR='nano'

to .bash_profile to switch default editor to Nano.
Nano maybe is less powerful but much more intuitive for new bash users (to be honest I still use it and don't want invest my time into vim). And another thing that it is almost on all linux distributions as I know so you don't have to switch from nano editor on your local machine to vim on remote instances

Collapse
 
daviddeejjames profile image
David James

Coders need the Shell to do their job best. It's not going anywhere. No matter how uncomfortable you are in the start, take a deep breath and start using it

Super great article, as someone who loved using GUI's I was pretty against learning terminal at first until I saw how powerful and necessary it was to becoming a Web Developer.

Collapse
 
maxwell_dev profile image
Max Antonucci

I felt the same for the start of my career too. For git source control I kept using SourceTree due to its GUI until I saw I was missing out on so much of its functionality that way.

Collapse
 
ashleyjsheridan profile image
Ashley Sheridan

Worth mentioning that Bash is the default shell of most Linux distributions. Given Linux is the most popular operating system in the world, and that Bash is available on Mac and Windows too, it's definitely worth learning.

Collapse
 
ikemkrueger profile image
Ikem Krueger • Edited

With Bash, you can run cd ~ to get to your root directory

It is getting you to your „home“ directory.

A single „cd“ hit by the enter key, does the same as „cd ~“.

Collapse
 
190245 profile image
Dave • Edited

Vim is, at its core, a text-editor. It's built into the Shell

Nope, it's really not. Whatever shell you're using, vim is an application in its own right. Same as the shell is an application.

Most of the time, when I'm installing a new OS, vim isn't even installed by default (but various shell's are).

 
eljayadobe profile image
Eljay-Adobe

As a desktop OS, I've tried Yellow Dog Linux, DEC Alpha Tru64 UNIX, and Solaris. (By "desktop" I assume you mean it uses KDE or Gnome or somesuch, and is GUI based with a mouse.)

As a terminal-style OS, I've used Microsoft Xenix. (That was before Xenix was spun off into SCO... and we all know how that story ends.)

I've not used OpenBSD nor FreeBSD. But since I'm a Theo de Raadt fanboy, well OpenBSD is more my bag. On a lark, I have used Darwin for about a week, which owes some lineage to FreeBSD.

All that being said, I also have a warm spot in my heart for Amiga. I am sometimes tempted to get the latest Amiga -- currently A-EON's AmigaOne X5000. But then I open my wallet and see the tumbleweeds blow out of it.

Collapse
 
qm64 profile image
qm64

Follow on, my fav unmentioned commands are:

  • find
  • xargs
  • less
  • tee
  • cut
  • paste
Collapse
 
linuxkarl615 profile image
Karl Haines

Very simple and to the point, funny that I've been using a linux shell for 27 years now but I actually took the time to read your article just to see how you did! I guess you drew in my interest somehow, lol. The shadow knows. Anyway, you did great and clearly are talented with such things! Keep up the good work and before too long opensource will finally take over the world!

:)

Karl (linuxkarl615)

Collapse
 
fannyvieira profile image
Fanny

Great!

Collapse
 
ben profile image
Ben Halpern

Brilliant post Max!

Collapse
 
maxwell_dev profile image
Max Antonucci

Aww shucks :)

Collapse
 
victoryshoe profile image
Victor Shi

I've used the shell quite a bit out of necessity, but this high-level overview has done wonders for bringing my existing knowledge together as well as making me want to learn more!

Collapse
 
antogarand profile image
Antony Garand • Edited

cd ~ - go to your root directory

This should be home and not root, / would be the root directory!

Collapse
 
crypt0mek profile image
Crypt0mek

"You use a Mac, since you have a soul and all" - very weird assumption :) but i like the rest

Collapse
 
5n4p_ profile image
Andreas Schnapp

It's not a assumption, he wrote's to his self in the past, so he know's that he uses a Mac since he have a soul ;)

Collapse
 
danjconn profile image
Dan Conn

Nice! Thanks dude!

Collapse
 
eljayadobe profile image
Eljay-Adobe

Alas, the software I write has to run on macOS.

Not sure how easy it would be to setup a toolchain on FreeBSD to produce macOS executables. (I'd probably pick OpenBSD over FreeBSD.)

Collapse
 
bobbyiliev profile image
Bobby Iliev

Great post! 🙌

You should check out this Open-Source Introduction to Bash Scripting Ebook on GitHub as well!:

github.com/bobbyiliev/introduction...

Collapse
 
babuasian profile image
babuasian

Appreciate the way the subject is dealt and made attractive, right from the start.

Kudos..

Collapse
 
iglesk profile image
Omar AlSabek

Amazing, Amazing, Amazing !! thanks so much, it's really the shell introduction i wish i had!

Collapse
 
tux0r profile image
tux0r

You should get familiar with Bash, since it's likely your default shell.

Mac OS had had the Unix standard shell tcsh instead - for years. So does FreeBSD. Others use the ash or the ksh. :)