Skip to content

Instantly share code, notes, and snippets.

@megawertz
Created October 17, 2013 01:27
Show Gist options
  • Star 31 You must be signed in to star a gist
  • Fork 18 You must be signed in to fork a gist
  • Save megawertz/7017879 to your computer and use it in GitHub Desktop.
Save megawertz/7017879 to your computer and use it in GitHub Desktop.
Some basic bash snippets I use to introduce shell scripting to my Linux class.
#!/bin/bash
# viewing environment variables
echo "The value of the home variable is: "
echo $HOME
# issue a command
echo "The output of the pwd command is: "
pwd
# that's boring, grab output and make it readable
echo "The value of the pwd command is $(pwd)"
# assign command output to a variable
output=$(pwd)
echo "The value of the output variable is ${output}"
# view data on the command line
echo "I saw $@ on the command line"
# read data from the user
echo "Enter a value: "
read userInput
echo "You just entered $userInput"
# concatenate userinput with command output
echo "Enter a file extension: "
read ext
touch "yourfile.${ext}"
# check to see if a file exists
if [ -d /etc/sysconfig ]; then
echo "That file is there and a directory"
else
echo "Not there or not a directory"
fi
@Dalmar2
Copy link

Dalmar2 commented Sep 1, 2018

thanks well Sir

@dryster
Copy link

dryster commented Jan 29, 2019

Thanks Jason. I'm an old man learning the basics of a Raspberry Pi and this stuff helps!

@voa2000
Copy link

voa2000 commented Feb 7, 2019

Thanks for sharing these scripts.

@cbvallance
Copy link

Thanks for your time!

@tobbtechnologies
Copy link

thanks a lot

@rianputrarama
Copy link

Thanks for sharing Sir

@Sekander16F84
Copy link

I appreciate your work and the way you teach it is awesome. Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment