Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Shell script
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Shortcuts=== A shell script can provide a convenient variation of a system command where special environment settings, command options, or post-processing apply automatically, but in a way that allows the new script to still act as a fully normal [[Unix command]]. One example would be to create a version of [[ls]], the command to list files, giving it a shorter command name of <code>l</code>, which would be normally saved in a user's <code>bin</code> directory as <code>/home/''username''/bin/l</code>, and a default set of command options pre-supplied. <syntaxhighlight lang="sh"> #!/bin/sh LC_COLLATE=C ls -FCas "$@" </syntaxhighlight> Here, the first line uses a [[#Configurable choice of scripting language|shebang]] to indicate which interpreter should execute the rest of the script, and the second line makes a listing with options for file format indicators, columns, all files (none omitted), and a size in blocks. The <code>LC_COLLATE=C</code> sets the default collation order to not fold upper and lower case together, not intermix [[dotfile]]s with normal filenames as a side effect of ignoring punctuation in the names (dotfiles are usually only shown if an option like <code>-a</code> is used), and the <code>"$@"</code> causes any parameters given to <code>l</code> to pass through as parameters to ls, so that all of the normal options and other [[programming language syntax|syntax]] known to ls can still be used. The user could then simply use <code>l</code> for the most commonly used short listing. Another example of a shell script that could be used as a shortcut would be to print a list of all the files and directories within a given directory. <syntaxhighlight lang="sh"> #!/bin/sh clear ls -al </syntaxhighlight> In this case, the shell script would start with its normal starting line of <span style="font-family:courier">#!/bin/sh</span>. Following this, the script executes the command <span style="font-family:courier">clear</span> which clears the terminal of all text before going to the next line. The following line provides the main function of the script. The <span style="font-family:courier">ls -al</span> command lists the files and directories that are in the directory from which the script is being run. The <span style="font-family:courier">[[ls]]</span> command attributes could be changed to reflect the needs of the user.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)