Getting to know Linux, Starting from nothing, Mastering Bash

I know I am only a year or two into my Linux journey, but after spending my life on computers, starting with my Radio Shack TRS 80 (yes, I'm old), a C64 and even an Amiga, I found myself starting Windows at 3.1. I would not be surprised to learn I have spent some portion of every day since on a computer, so I knew Linux would be a learning curve, but holy 300mbs modem, Batman, I have read some of the posts in here and it's like a lot of you are speaking a whole new language.

I find myself reading books like The Linux Command Line and taking online classes for scripting. It's crazy. People have always come to me for help with their PCs, including repair and barebones builds. But here, I feel like... IDK... an old man trying to program his VCR. Lol.

Anyway, any resources you all can point me to would be appreciated. In the meantime, if I say something that does not sound right, please correct me so I can learn how not to feel like an old dude.

:smiley:

3 Likes

What you are asking is a question having so very broad a scope as to be potentially overwhelming!

I will assume that you are looking for a limited, but sufficient scope for being able to use and, to a limited extent, adapt your OS installation in order to make it fit you like a glove. For that, I will come back in another posting with the list of the few books that should offer that coverage.

But to help put that into context, or in case my assumption is incorrect, I will try to give you a "sense" of the scope of things, just to give you an idea of the journey you may be embarking upon. :slight_smile:

Below is an attempt at putting on display the various "silos" that represent topics of specialization within the Linux ecosystem.

Maybe, as you go over those,

  • you might be able to recognize and help to pin that down a bit of your specific focus, if that applies, by indicating which of the following topics are of most urgent concern, or,
  • if a number of them, reply with your list being ordered in what your sense of priority would be, or
  • if your are looking for a suggested sequence for a reading list that provides a hierarchy of gradually more complex learning?

If this last one, you will need to be specific about the "end goal" or specific competency you are hoping to achieve, if you have been able to identify that by yourself or with help of advisors.

Topics that could be covered include (not intended to be fully comprehensive):

OS - Linux generic

  • [1] basic user interaction with OS and mastery of personal content on disk

    • Linux command usage
    • text editors (programming), pros/cons, capabilities, limitations (Gvim, Emacs, etc.)
    • various archiving formats, their purposes (intended preferred uses), limitations
    • browser options, pros/cons, capabilities, limitations, exposures (Firefox, Chrome, Chromium, Falkon, etc.)
    • desktop Office tools (OpenOffice, LibreOffice, etc.)
    • desktop communication tools (email, RSS, messengers, VOIP, "video-phone", group video-conferencing, shared blackboard, etc.)
    • security applications (password management, public-key encryption, key-lookup sites, encrypted email, ISP VPN, user-to-user VPN, network obfuscation a.k.a Tor-facilitated networking)
  • [2] basic OS utility functions

    • security applications (level 1 - privilege clamp-down on all users, applications, services, ports)
    • disk setup, disk check/repair, data/disk backup, data/disk restore, fdisk, gdisk, parted, gparted
  • [3] intermediate User capabilities

    • IDEs a.k.a. Integrated Development Environments for Software Development (Builder, Geany, IDLE, CodeLite, Eclipse, etc.)
    • Software development practices - Infotech Industry generic
    • Software development practices - Linux ecosystem
    • Software development practices - Debian-derivative ecosystem
    • Software development practices - Ubuntu ecosystem
    • Software development practices - UbuntuMATE ecosystem
  • [4] intermediate OS utility functions

    • security applications (level 2 - virus/trojan scan/detection/containment)
    • security applications (level 3 - penetration testing and prevention)
  • [5] advanced Desktop utility functions

    • desktop fulltext harvesting/indexing/search capabilities (Recoll, etc.)
  • [6] advanced OS utility functions

    • security applications (level 4 - breach event monitoring, detection, response)
    • installation of OS "extensions" using Package Managers
    • installation/build of Kernel customizations
    • startup disk creator
    • etc.
  • [7] advanced service deployment

    • installation and management of database capabilities (MySQL, MariaDB, SQLite, etc.)
    • installation and management of mail servers
    • installation and management of Domain Name Services
  • [8] expert OS utility functions

    • firewall administration
    • proxy administration
    • router and border gateway administration
    • building a customized distro and deploy as bootable installation media

OS - UbuntuMATE Specific

  • [9] standard applications and GUI-based utilities
    • Caja
    • EOM
    • etc.

Linux Ecosystem - 3rd-Party Cross-Distro Applications

[10]

  • Synaptic
  • Blender
  • FreeCAD
  • Gimp
  • Inkscape
  • Scribus
  • Shotwell
  • Transmission
  • Liferea
  • Grisbi
  • Calibre
  • Manuscript
  • Okular
  • Sigil
  • Document Scanner
  • Fontmatrix
  • Handbrake
  • RipperX
  • VLC
  • Widelands
  • and many, many more ...

I hope that can help you guide us to identify the book/site references you are looking for, that will meet your needs. :slight_smile:

2 Likes

Thanks Eric... I appreciate it.

I have been pretty successful researching and finding apps I really enjoy, so I am good there. My gaps seem to be in things like stringing together multiple commands in the terminal or launching actual programs. For example, I use Planify so I open the terminal and try and launch it and it says there is no such program. On the other hand, I can type in gimp and GIMP launches just fine.

I am also big into automation, so scripting seems to be one of my immediate focuses, and I recently learned about assigning variables as a command and that interests me as well.

I am a closet coder and while not having done it professionally, I do code python, html, css and javascript so a lot of the tools I used in Windows... those skills are transferable to linux versions of text editors so no problems there. I also started my Linux life installing Ubuntu Touch on older phones so fortunately, a lot of my previous computer life is transferable.

So I think, in the near term, scripting and automation as well as a better command of the terminal are my interests.

Anyway, thanks for taking the time to compose such a long reply. I was not expecting something like, just maybe some links to a few of folks favorite resources or places people thought would be a good place for me to start.

Thanks again.

The issue with Planify might just be that you haven't added the string defining the PATH prefix to locate Planify.

You would do that by changing your PATH in your .bashrc (or .bashrc_local) from

setenv PATH={previous_definition}

do

setenv PATH="${pathPrefixForPlanify}:${previous_definition}

Some applications, like GIMP, install in standard locations.

However, I looked up Planify. Is it installed in something like a snap? I see a reference to Flatpack, which is supposed to be similar. If so, you need to ask Planify/Flatpack how they expect you to "integrate" the application into your environment for useability.

Beyond that, I would invite you to peruse my scripts that I've uploaded on GitHub at your leisure. :slight_smile:

I will come back tomorrow with a list of book titles which I think will be appropriate to your objective and you level of "hack" ability. :slight_smile:

2 Likes

Yes, Planify is Flatpak. I will have to check into that.

And as a graphic designer, I already lifted your convert scripts. :slight_smile:

Thanks for everything. Really.

Welcome to the club! :smiley:
My first program was in Fortran IV (mind a heap of punch-cards) and the system to execute it was IBM 360/370 :man_shrugging:

Reading some Unix/Linux books is an excellent way to introduce oneself into that new reality. And since then (IMHO) the best way is to 'google' for anything and everything of interest. Surprisingly (or not?) there are many specific answers to specific questions which really teach us Unix/Linux.

Good luck!

4 Likes

I would like to point you to one useful site for beginners:

ShellCheck

That provides coding quality and debugging advice for script without need for execution.

There is also this gem, again a good point for beginners:

Heiner's SHELLdorado

As for the promised books ...

Focus: Basic to Advanced Scripting, with a bit of OS-related

[1] Linux Command Line and Shell Scripting Bible

  • Richard Blum, 809 pages, Wiley, 2008
  • basic full coverage of what a user needs to know

[2] Wicked Cool Shell Scripts - 101 Scripts for Linux, OS X, and UNIX Systems

  • Dave Taylor and Brandon Perry, 366 pages, no starch press, 2017
  • Dave had a column in the Linux Journal

[3] Shell Scripting: Expert Recipes for Linux, Bash, and More

  • Steve Parker, 564 pages, Wiley, 2011
  • lots of stuff that could interest a beginner

[4] Linux Programming Unleashed

  • Kurt Wall, Mark Watson, and Mark Whitis, 818 pages, Sams, 1999
  • offers a good progression thru gradually more complex topics

Focus: Level 1 Development - Basic Code Revision Management

[4] RCSβ€”A System for Version Control (Paper)

  • Walter F. Tichy, 19 pages, "Software: Practice and Experience", July 1985
  • you may also wish to visit RCS HOWTO by Paul Heinlein
  • what I use for Version Control of my personal coding, because it is simple and straightforward

https://www.gnu.org/software/rcs/

[5] The Pragmatic Programmer

  • Andrew Hunt, David Thomas, 321 pages, Addison Wesley Longman, 2000
  • a very good overview with lots of "earthy" wisdom

Focus: Level 2 Development - Advanced Development

[6] Coders at Work (eBook)

  • Peter Seibel, 733 pages, Manning, 2009
  • insights and wisdom from well-reputed and experienced developers

[7] User Journey Mapping: Visualize User Research, Brainstorm Opportunities, and Solve Problems

  • StΓ©phanie Walter, 78 pages, SitePoint, 2022
  • even if you don't adopt fully structured development methodologies, skimming thru this one could help guide how you approach the putting together of the puzzle pieces for your various projects. :slight_smile:

[8] Planning Extreme Programming

  • Kent Beck, Martin Fowler, 160 pages, Addison Wesley, 2000
  • how to contain and manage the chaos and risk associated with projects that are not well understood

[9] Professional Git

  • Brent Laster, 480 pages, Wrox, 2016
  • if you plan to interact with the current developers, for most projects, this is their core tool

Focus: Large-Scale Development

[10] Hands-on Domain-driven Design - by example
(Domain-driven Design practically explained with a massive case study)

  • Michael PlΓΆd, 285 pages, Leanpub, 2020
  • this is like being a silent intern glacing over a professional developers shoulder, working thru the process from start to finish (it is massive)

IF ... there is any topic of interest that is not covered by the above, let me know, and I will dig to see what I can find. :slight_smile:

Enjoy!

4 Likes

Hey Eugene, my own first program was, like you ...
... using Fortran IV ...
... on punched cards ...
... on IBM 360 ...
... at McGill in 1974!

Ahhhhh ... if only we could relive those days! :slight_smile:

3 Likes

Thanks for this. I really appreciate you taking the time to help.

My linux learning for today was creating my first .bash_aliasas file. It's little things like this I love about linux. I know you can create aliases in windows powershell, but it is not as straightforward as this.

A few more things ...

  • Mastering Linux shell scripting,
    Mokhtar Ebrahim and Andrew Mallett, 2018

  • Command Line Kung Fu,
    Jason Cannon, 2014

  • Bash Notes For Professionals,
    GoalKicker (Stack Overflow Documentation), 2016

The GoalKicker site has many more free eBooks that might interest you for the other languages that you have programmed in. :slight_smile:

And ... don't know if you've come across these, there are many different publishers of articles about

  • "The first things to do after installing Ubuntu {pick_your_version}".

For example,

One last thing. This site might show things that might pique your interest. It will expose you to "random" things. That's the best way to describe it. I think I will stop there! :slight_smile:

3 Likes

I would also like to point out a technique used in shell scripting (bash or otherwise).

Let's say that you have some some standard shell functions that you want to be able to "re-use" elsewhere. There is a technique for doing that, without copy+pasting that identical code into each script. I've seen people refer to that as the "dot" technique. The technique loads the functions as part of the shell calling the functions, and NOT as a sub-shell.

For example, take this piece of coding (a basic collection of functions):

"Bash Header" file 00__BashHeader_FunctionLibrary.bsh:

####################################################################################################
####################################################################################################
#
#	WARNING - This HEADER file is intended for being called ONLY from BASH, not BOURNE shell!!!
#
#	usage:	. 00__BashHeader_FunctionLibrary.bsh
#
####################################################################################################
####################################################################################################
#
###  Bash Header Function:  yesno
#	Display user-supplied prompt-string and return a 
#	standardized value for Yes/No decision.
#
###  Returns: global variable YESNO
#	IF empty value returned, implies invalid response.
#
####################################################################################################
####################################################################################################
#
#       Signal        x86/ARM     Alpha/   MIPS   PARISC   Notes
#                   most others   SPARC
#       ─────────────────────────────────────────────────────────────────
#       SIGHUP           1           1       1       1
#       SIGINT           2           2       2       2
#       SIGQUIT          3           3       3       3
#       SIGILL           4           4       4       4
#       SIGTRAP          5           5       5       5
#       SIGABRT          6           6       6       6
#       SIGIOT           6           6       6       6
#       SIGBUS           7          10      10      10
#       SIGEMT           -           7       7      -
#       SIGFPE           8           8       8       8
#       SIGKILL          9           9       9       9
#       SIGUSR1         10          30      16      16
#       SIGSEGV         11          11      11      11
#       SIGUSR2         12          31      17      17
#
#       SIGPIPE         13          13      13      13
#       SIGALRM         14          14      14      14
#       SIGTERM         15          15      15      15
#       SIGSTKFLT       16          -       -        7
#       SIGCHLD         17          20      18      18
#       SIGCLD           -          -       18      -
#       SIGCONT         18          19      25      26
#       SIGSTOP         19          17      23      24
#       SIGTSTP         20          18      24      25
#       SIGTTIN         21          21      26      27
#       SIGTTOU         22          22      27      28
#       SIGURG          23          16      21      29
#       SIGXCPU         24          24      30      12
#       SIGXFSZ         25          25      31      30
#       SIGVTALRM       26          26      28      20
#       SIGPROF         27          27      29      21
#       SIGWINCH        28          28      20      23
#       SIGIO           29          23      22      22
#       SIGPOLL                                            Same as SIGIO
#       SIGPWR          30         29/-     19      19
#       SIGINFO          -         29/-     -       -
#       SIGLOST          -         -/29     -       -
#       SIGSYS          31          12      12      31
#       SIGUNUSED       31          -       -       31

function trapAndExit {
	local exitActions="$1"
	local exitCode="$2"
	local qualifier="$3"

	trap { ${exitActions} } 1	###  TBD - whether defining this inside the function is legal

	case "${exitCode}" in
		"F1" )	echo "\t Filename was not provided as expected by parameter [${qualifier}]!"
			exit 1
			;;
		"F2" )	echo "\t File [${qualifier}] is missing!"
			exit 1
			;;
		"F3" )	echo "\t File [${qualifier}] is empty!"
			exit 1
			;;
		"F4" )	echo "\t CONFLICT!  File [${qualifier}] already exists!"
			exit 1
			;;
		"F5" )	echo "\t RESTRICTIONS!  Access to file [${qualifier}] is denied!"
			exit 1
			;;
		"D1" )	echo "\t Directory name not provided as expected by parameter [${qualifier}]!"
			exit 1
			;;
		"D2" )	echo "\t Directory [${qualifier}] is missing!"
			exit 1
			;;
		"D3" )	echo "\t Directory [${qualifier}] is empty!"
			exit 1
			;;
		"D4" )	echo "\t CONFLICT!  Directory [${qualifier}] already exists!"
			exit 1
			;;
		"D5" )	echo "\t RESTRICTIONS!  Access to directory [${qualifier}] is denied!"
			exit 1
			;;
		   * )	echo "" ;
		   	exit 1
			;;
	esac
	RETURN_VALUE=0		### Bash built-in for function's exit return code
} #END function trapAndExit


####################################################################################################
####################################################################################################
#
###  Bash Header Function:  choice
#	Display user-supplied prompt-string and return a 
#	standardized value for numerical identifier selected.
#
###  Returns: global variable CHOICE
#	IF empty value returned, implies invalid response.
#
####################################################################################################
####################################################################################################
function choice {
	CHOICE=''
	local pString="$*"
	local entry
	read -p "${pString}" entry
	case "${entry}" in
		[0-9] | 1[0-9] | 2[0-9] )	CHOICE="${entry}" ;;
				      * )	CHOICE="" ;;
	esac
	RETURN_VALUE=0		### Bash built-in for function's exit return code
} #END function choice


####################################################################################################
####################################################################################################
#
###  Bash Header Function:  yesno
#	Display user-supplied prompt-string and return a 
#	standardized value for Yes/No decision.
#
###  Returns: global variable YESNO
#	IF empty value returned, implies invalid response.
#
####################################################################################################
####################################################################################################
function yesno {
	YESNO=''
	local pString="$*"
	local entry
	read -p "${pString}" entry
	case "${entry}" in
		[yY] ) YESNO='y' ;;
		    * ) YESNO="n" ;;
	esac
	RETURN_VALUE=0		### Bash built-in for function's exit return code
} #END function yesno

If you wanted to use the "yesno" function in a script, you would to the following:

. 00__BashHeader_FunctionLibrary.bsh

YESNO=""

yesno "Do you wish to continue ? [y|N] => "

case ${YESNO} in
	y* ) doit ;;
	* ) echo "Abandoning" ; exit 1 ;;
esac

You could rework that yesno function ( bottom of what I call a bash header file) such that RC=0 is yes and RC=1 is no ... to simplify the coding to handle the result. :slight_smile:

1 Like

Thank you eric for sharing such a important facts!

2 Likes

Hi,@sandiesarai and welcome to the Ubuntu MATE Community!

No holy wars here intended. Just my personal point of view. Knowledge of bash artefacts and the basics of bash scripting is very useful (and almost a must) without any doubts.

Nevertheless, writing something beyond simple and/or trivial in .sh very quickly results in bloated, unreadable and not comprehensive code. That is just a consequence of shell's interpreter language. More often than not one finds oneself using wild bash-specific tips and tricks for doing thing which are supposed to be obvious enough in a conventional programming language.

All in all, since the rise of Python I personally prefer to script everything in Python. First, it is Π° full-fledged language without limitations. Second, it is implemented as an interpreter and retains convenience of scripting itself.

Hopefully, this will help!

https://python-for-system-administrators.readthedocs.io/en/latest/

2 Likes

Hey Eugene, I will not dispute your stated claims regarding possible advantages of Python. I've "delved" into that when I had to. I just find that "column position" for line start is a very difficult one for me to wrap my mind around, because I prefer concrete delimiters for "segment wrappers", which is why I gravitate to awk or C or Pascal, vs sed or other languages. Even with clear delimiters, some languages, notably Prolog, are very hard to wrap your thinking around. ... at least that is my experience.

Important lesson, and I think that was your main point, is that each of us has to explore the various tools in the Linux ecosystem and gravitate towards those for which we individually have an affinity, a comfort level which keeps us from stumbling and struggling as we try to do things. :slight_smile:

I'm actually pretty strong with Python, but I wanted to get a grasp of the linux terminal and linux in general, and I thought learning scripting would be a solid approach.

1 Like

You are correct, Eric. I just intended to point out just another (IMHO worthwhile one) approach to scripting.

1 Like

I see, Stephen. Well, sometimes chaining bash commands, awk and sed feels like a bit nightmarish undertaking... Just for the case I'd like to mention that there is another approach to scripting.

1 Like

I may quickly come to realize just that, but this is me trying to learn something new. I don't have any real critical need to do scripting and if I did, I would use python... which is right in python's wheelhouse.

I do appreciate the suggestion tho... everyone has been very helpful and it is appreciated.

1 Like

Heh! My first was on an IBM 6400 Electronic Accounting Machine, using a plugboard. Later came 360, 370, a few homebrew computers, C64, Vic 20, C128 Amiga, On to Wndows (forced by change of job), and finally got fed up with Microsoft, and here I am