Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Shell script
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
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.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Shell script
(section)
Add topic