How do I set or create variables within my shell script or at command line under Linux and Unix like operating systems?
You can easily create and set variables within a script using the following syntax:
variable=value x=5 y=10 dest=/nas05/backup today="Monday"
value is assigned to given variable and value must be on right side of = (equal) sign. If value is not given, the variable is assigned the null string. In this example set shell variable called dest to /nas05/backup/full, enter:
dest="/nas05/backup/full"
To display the value of a variable called dest, enter:
echo "$dest"
OR
echo "${dest}"
OR
printf "%s\n" dest
See also:
- Assign values to shell variables - from the Linux shell scripting tutorial wiki.
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop











{ 0 comments… add one now }