Command (computing): Difference between revisions

Content deleted Content added
Directive is not wrong, but instructions seems easier to consume; scripting is a command way to use commands
Examples: Less folksy (here some...); more accurate by identifying bash not just an OS (Unix)
Line 14:
 
==Examples==
Here are some commands given to a [[command-line interpreter]] ([[Unix shell]]).
 
A notable context in which commands are prevalent is the [[operating system]] [[shell (computing)|shell]]. Commonly, the shell dispatches a command to a program that has a file name matching the first parameter. In a [[Unix shell]] (such as [[Bash (Unix shell)|bash]] and many related variants), the match must be exact including case. The following bash command changes the [[working directory]] to ''/home/pete'' by invoking the program ''[[Cd (command)|cd]]'':
The following command changes the user's working position in the [[directory tree]] to the directory ''/home/pete''. The utility program is ''[[Cd (command)|cd]]'' and the argument is ''/home/pete'':
<syntaxhighlight lang="bash">
cd /home/pete
</syntaxhighlight>
 
The following bash command printswrites the text ''"Hello World''" onvia theprogram [[standardEcho output(command)|echo]] stream,to which,[[standard inoutput]] this{{endash}} case, just printstypically the text on the screen. The program name is [[Echocomputer (command)terminal|echoterminal]] and the argument is "Hello World". TheQuotes quotesaround arethe usedtwo towords preventindicate ''Hello''that andthe ''World''phrase beingis treated as separatea tokens:single parameter.
echo "Hello World"
 
<syntaxhighlight lang="bash">
The following commands are equivalent. They list files in the directory ''/bin''. The program is ''[[ls]]'', having three flags (''l'', ''t'', ''r''), and the argument is the directory ''[[Filesystem Hierarchy Standard|/bin]]'':
echo "Hello World"
ls -l -t -r /bin
</syntaxhighlight>
ls -ltr /bin
 
The following demonstrates how the default behavior of a command is modified with a switch. The switch {{code|-e}} causes the command to treat characters prefixed with a backslash as the associated control character. In this case {{code|\t}} results in a tab character.
The following command displays the contents of the files ''ch1.txt'' and ''ch2.txt''. The program name is ''[[cat (Unix)|cat]]'', having two file name arguments:
cat ch1.txt ch2.txt
 
<syntaxhighlight lang="bash">
Here are some commands for the [[DOS]], [[OS/2]] and [[Microsoft Windows]] [[Cmd.exe|command prompt]] processor. The following command displays the contents of the file ''readme.txt''. The program name is ''[[TYPE (DOS command)|type]]'' and the argument is ''readme.txt''.<ref>{{cite web | url = https://ss64.com/nt/type.html | access-date = 14 March 2019 | title = Type - Display a text file - Windows CMD | publisher = SS64.com }}</ref>
echo -e "Hello\tWorld"
type readme.txt
</syntaxhighlight>
 
TheIn followingshells such as [[Cmd.exe|command listsprompt]], the[[DOS]], contentsand of[[OS/2]] thesome currentcommands directory.are Thebuilt-in; are not implemented as a separate program. nameBut, isif ''[[Dira (command)|dir]]'' is not built-in, andthen the shell dispatches to a program that has an executable extension (such as ''Q.exe'') isand abase flagname requestingmatching thatthe first parameter ignoring case. The following command displays the ownercontent of each file also''readme.txt'' bevia listedthe built-in command ''[[TYPE (DOS command)|type]]''.<ref>{{cite web | url = https://ss64.com/nt/dirtype.html | access-date = 14 March 2019 | title = DIRType - listDisplay filesa andtext foldersfile - Windows CMD | publisher = SS64.com }}</ref>
 
dir /Q
<syntaxhighlight lang="batch">
type readme.txt
</syntaxhighlight>
 
Here are some commands for the [[DOS]], [[OS/2]] and [[Microsoft Windows]] [[Cmd.exe|command prompt]] processor. The following command displayslists the contents of the filecurrent ''readme.txt''.directory Thevia programbuilt-in name iscommand ''[[TYPEDir (DOS command)|typedir]]''. and the argumentThe isswitch ''readme.txt/Q'' modifies default behavior to include owner information.<ref>{{cite web | url = https://ss64.com/nt/typedir.html | access-date = 14 March 2019 | title = TypeDIR - Displaylist afiles textand filefolders - Windows CMD | publisher = SS64.com }}</ref>
 
<syntaxhighlight lang="batch">
dir /Q
</syntaxhighlight>
 
== See also ==