...
Code Block |
---|
|
FOO="Hello world!"
echo "The value of variable 'FOO' is \"$FOO\"" # Escape the double quotes inside double quotes
echo "The value of variable 'FOO' is"' "'$FOO'"' # Single-quoted text after double-quoted text
|
...
Code Block |
---|
|
date # Calling the date command just displays date/time information
echo date # Here "date" is treated as a literal word, and written to output
echo `date` # The date command is evaluated and its output replaces the command
today=$( date ); echo $today # environment # Assign a string including today's date to variable "today" is assigned
today's date
today="Today is: `date`"; echo $today # "today" is assigned a string including today's date |
The slightly odd syntax $(<some command>), is equivalent to `<some command>`, and can be easier to read when the command to be evaluated is complex.
Code Block |
---|
|
echo "Today is: `date`"
echo "Today is $(date)"
|
Exercise 3-5
How would you output this text using a command to calculate the number of lines: The haiku.txt file has 11 lines
...
Code Block |
---|
|
ls haiku.txt xxx.txt 1> stdoutout.txt 2>stderr2>err.txt
cat stdoutout.txt # Displays "haiku.txt"
cat stderrerr.txt # Displays "ls: cannot access 'xxx.txt': No such file or directory" |
...
- Use a command-line program that lets you enter/edit text in a Terminal window (e.g. nano, vi/vim, emacs)
- nano is extremely simple and is a good choice as a first local text editor
- warning: nano has a tendency to break long single lines into multiple lines
- vi and emacs are extremely powerful but also quite complex
- Use a text editor or IDE (Integrated Development Environment) program that runs on your local computer but has an SFTP (secure FTP) interface that lets you connect to a remote computer
- E.g.,Komodo IDE (Windows & Mac) or Notepad++ (Windows). Both are no-cost.
- Once you connect to the remote host, you can navigate its directory structure and edit files.
- When you open a file, its contents are brought over the network into the text editor's edit window, then saved back when you save the file.
- Use software or protocols that allow you to "mount" remote server directories
- Once mounted, the remote storage appears as a local volume/drive.
- Then, you can use any text editor or IDE on your local computer to open/edit/save remote files.
- Software programs that can mount remote data include ExpanDrive for Windows or Mac (costs $$, but has a free trial), TextWrangler for Mac.
- Remote file system protocols include Samba (Windows, Mac) and NFS (Linux)
...