Podcast
Questions and Answers
What is the main strength of aliases and functions in shell scripting?
What is the main strength of aliases and functions in shell scripting?
What is the syntax for declaring an alias in shell scripting?
What is the syntax for declaring an alias in shell scripting?
What is the purpose of an alias in shell scripting?
What is the purpose of an alias in shell scripting?
What is the relationship between variables, aliases, and functions in shell scripting?
What is the relationship between variables, aliases, and functions in shell scripting?
Signup and view all the answers
What is the benefit of using aliases and functions in shell scripting?
What is the benefit of using aliases and functions in shell scripting?
Signup and view all the answers
Study Notes
Customize and Use the Shell Environment
- Set environment variables at login or when spawning a new shell, e.g.,
PATH
. - Write Bash functions for frequently used sequences of commands.
- Maintain skeleton directories for new user accounts.
- Set command search path with the proper directory.
Environment Variables
-
/etc/bash.bashrc
and/etc/profile
are used to set environment variables. -
env
,export
,set
, andunset
are used to manipulate environment variables. -
~/.bash_profile
,~/.bash_login
,~/.profile
,~/.bashrc
, and~/.bash_logout
are used to set environment variables for individual users.
Bash Commands
-
source
command is used to load a file into the current shell. -
function
command is used to define a function. -
alias
command is used to define an alias.
Setting Language and Working Directory
-
export LANG=es_ES.UTF-8
sets the language of the current shell to Spanish UTF-8. -
pwd
command prints the name of the current working directory.
Setting and Using Variables
-
export PATH=$PATH:/home/carol/scripts
sets thePATH
environment variable to include a new directory. -
my_path=$PATH
sets the value ofmy_path
to the value ofPATH
. -
mammal=gnu
sets a local variablemammal
to the valuegnu
. -
var_sub="The value of mammal is $mammal"
sets a local variablevar_sub
using variable substitution.
Creating and Searching Environment Variables
-
export mammal=gnu
turns a local variable into an environment variable. -
set | grep mammal
andenv | grep mammal
are used to search for an environment variable.
Creating and Managing Directories
-
mkdir ~/bin
creates a new directory namedbin
in the home directory. -
export PATH=$PATH:~/bin
adds the~/bin
directory to thePATH
environment variable.
Adding to ~/.profile
-
if [ -d ~/bin ]; then export PATH=$PATH:~/bin; fi
is used to add the~/bin
directory to thePATH
environment variable in the~/.profile
file.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
Customize and use the shell environment. Set environment variables, write Bash functions, and maintain skeleton directories for new user accounts.