diff --git a/docs/website_as_latex/2018-11-19_04-03.tex b/docs/website_as_latex/2018-11-19_07-54.tex similarity index 93% rename from docs/website_as_latex/2018-11-19_04-03.tex rename to docs/website_as_latex/2018-11-19_07-54.tex index d89c38e..b31c2bf 100644 --- a/docs/website_as_latex/2018-11-19_04-03.tex +++ b/docs/website_as_latex/2018-11-19_07-54.tex @@ -1,4 +1,4 @@ -% File autogenerated using the Bonus 2 program at 2018-11-19 04:03 +1% File autogenerated using the Bonus 2 program at 2018-11-19 07:54 \documentclass[hidelinks,12pt,a4paper,numbers=enddot]{scrartcl} \usepackage[margin=2cm]{geometry} @@ -197,7 +197,7 @@ When it has completed its operation for the last file, \texttt{paste} will outpu character and move on to the next line. \begin{verbatim} -paste [flags] [file1] [file2] ... +paste \[flags\] \[file1\] \[file2\] ... \end{verbatim} Flags @@ -271,7 +271,7 @@ abcdefghi The syntax command is: \begin{verbatim} -colrm [first] [last] +colrm \[first\] \[last\] \end{verbatim} \begin{verbatim} @@ -305,14 +305,14 @@ from each file, precede each set of lines by the name of the file and separate each set of lines by one vertical space. \begin{verbatim} -head [flags] [file1] [file2] ... +head \[flags\] \[file1\] \[file2\] ... \end{verbatim} The \texttt{tail} command is similar to the \texttt{head} command except that it reads the final lines in files rather than the first lines. \begin{verbatim} -tail [flags] [file1] [file2] ... +tail \[flags\] \[file1\] \[file2\] ... \end{verbatim} Flags @@ -398,7 +398,7 @@ Huawei \end{verbatim} The syntax command is: -\begin{verbatim}grep [flag] [keyword] [file]\end{verbatim} +\begin{verbatim}grep \[flag\] \[keyword\] \[file\]\end{verbatim} You can put different flags together to refine the search. \begin{verbatim} @@ -508,7 +508,7 @@ Videogame \end{verbatim} The syntax command is: -\begin{verbatim} nl [flags][file] \end{verbatim} +\begin{verbatim} nl \[flags\]\[file\] \end{verbatim} \begin{verbatim} nl example.txt @@ -527,7 +527,7 @@ How you can see the command has numbered the lines. \begin{itemize} \item \textbf{-b (regex)}: Specify the lines to be numered \begin{verbatim} -nl -b p\^[cv] example.txt +nl -b p\^\[cv\] example.txt 1 Car 2 Computer 3 Videogame @@ -615,7 +615,7 @@ Pizza The syntax command is: \begin{verbatim} -comm [flag][file1] [file2] +comm \[flag\]\[file1\] \[file2\] \end{verbatim} \begin{verbatim} @@ -869,7 +869,7 @@ An alternate backup suffix may be specified via the -B option's argument.\\ Basic syntax is in the form \begin{verbatim} -install [OPTION]... SOURCE DEST +install \[OPTION\]... SOURCE DEST \end{verbatim} This line of code copies all .xyz file from \emph{/source/folder} to \emph{/destination/folder} @@ -913,7 +913,7 @@ So, first of all, you need to download Unarchiver in order to use this command.\ The basic syntax is: \begin{verbatim} -7z [adeltux] [-] [SWITCH] \texttt{\textless ARCHIVE_NAME\textgreater \textless ARGUMENTS\textgreater } +7z \[adeltux\] \[-\] \[SWITCH\] \texttt{\textless ARCHIVE\_NAME\textgreater \textless ARGUMENTS\textgreater } \end{verbatim} Here some useful options that we will use to explain some examples: @@ -945,7 +945,7 @@ There are many type of switches, we will see the most common ones. Specifies the compression method \begin{verbatim} --m\textless method_parameters\textgreater +-m\textless method\_parameters\textgreater \end{verbatim} The format for this switch depends on the archive type which are: @@ -965,7 +965,7 @@ Specifies the method of treating filenames or wildcards on the command line. The syntax: \begin{verbatim} --r[- | 0] +-r\[- | 0\] \end{verbatim} \begin{table}[h] @@ -1020,7 +1020,7 @@ Specifes which filenames or wildcards must be excluded from the operation. Syntax: \begin{verbatim} --x[\textless recurse_type\textgreater ]\textless file_ref\textgreater +-x\[\textless recurse\_type\textgreater \]\textless file\_ref\textgreater \end{verbatim} Sometimes we need to add files into an archive.7z, except one, this can be done as fllows: @@ -1043,7 +1043,7 @@ The command \texttt{md5} calculates an unique string for each input given as argument using the \emph{md5} algorithm. \begin{verbatim} -md5 [flags] [arg1] [arg2] +md5 \[flags\] \[arg1\] \[arg2\] \end{verbatim} Where \[flags\] are the (optional) md5 flags, read below for more info, @@ -1113,7 +1113,7 @@ The \emph{git} command providesa set of high-level operations and full access to Here is the basic syntax but commands may become some more complicated: \begin{verbatim} -git [flags] [path] +git \[flags\] \[path\] \end{verbatim} Start a working environment @@ -1164,7 +1164,7 @@ The ping command sends \textbf{ICMP Echo Request packets} to the remote server f Each \textbf{packet echoed back } (via an ICMP Echo Response packet) is written to the shell output. \begin{verbatim} - ping [-flag] server + ping \[-flag\] server \end{verbatim} The main usages for the \texttt{ping} command are: @@ -1257,7 +1257,7 @@ Flags With \texttt{shasum} command you can work with SHA Checksums. \begin{verbatim} -shasum [flag] [file] +shasum \[flag\] \[file\] \end{verbatim} Store the Checksum @@ -1315,7 +1315,7 @@ Usage The default basename command syntax is: \begin{verbatim} -basename [flags] [string] [suffix] +basename \[flags\] \[string\] \[suffix\] \end{verbatim} Where \[flags\] are the cat flags, read below for more info, the string command is @@ -1359,7 +1359,7 @@ By writing the command \texttt{base64} you can encode and decode Base64 data. The command follows the structure: \begin{verbatim} -base64 [flag] [-i input item] [-o output item] +base64 \[flag\] \[-i input item\] \[-o output item\] \end{verbatim} Defining input and output files @@ -1386,7 +1386,7 @@ Using the \texttt{-D} flag (which stands for decode), you obtain as output the input message decoded into binary data. \begin{verbatim} -base64 -D [-i input item] [-o output item] +base64 -D \[-i input item\] \[-o output item\] \end{verbatim} Summarize the tools @@ -1436,7 +1436,7 @@ The \texttt{chroot} utility allows you to change its root directory to the one indicated in newroot and, if given, executes the command.\\ \begin{verbatim} -chroot newroot [command] +chroot newroot \[command\] \end{verbatim} \section{watch} @@ -1557,7 +1557,7 @@ Usage: There are different syntaxes for this command: \begin{verbatim} -tar {-c} [options] [files | directories] +tar {-c} \[options\] \[files | directories\] \end{verbatim} The first one is the default syntax. Where \texttt{{-c}} stays for the @@ -1566,9 +1566,9 @@ we can use, \texttt{\[files | directories\]} for the files or directories what we want to compress. \begin{verbatim} -tar {-r | -u} -f archive-file [options] [files | directories] -tar {-t | -x} [options] [patterns] -tar [bundled-flags args] [file | pattern ...] +tar {-r | -u} -f archive-file \[options\] \[files | directories\] +tar {-t | -x} \[options\] \[patterns\] +tar \[bundled-flags args\] \[file | pattern ...\] \end{verbatim} The last one shows a bundled option word provided for compatibility with @@ -1684,7 +1684,7 @@ all sections of the object files except the (\_\_TEXT,\_\_text) section. \begin{verbatim} -strings [options] file_name(s) +strings \[options\] file\_name(s) \end{verbatim} Flags @@ -1894,7 +1894,7 @@ Usage The default fg command syntax is: \begin{verbatim} -fg [\%job_number] +fg \[\%job\_number\] \end{verbatim} The parameter \[\%job\_id\] contains the job number you wish to run in foreground. @@ -1909,7 +1909,7 @@ you need to press the \texttt{ctrl + Z} keys. The job number to be used with the \begin{verbatim} top \^Z -[1] + NNNN suspended top +\[1\] + NNNN suspended top \end{verbatim} \section{apropos} @@ -1925,7 +1925,7 @@ it will output all command related to the keyword \\ Example with the command \texttt{apropos archive}, the shell will output tar, zip ecc...\\ \begin{verbatim} -apropos [flags] keyword +apropos \[flags\] keyword \end{verbatim} Flags @@ -1952,7 +1952,7 @@ Usage The default passwd command syntax is: \begin{verbatim} -passwd [flags] [user] +passwd \[flags\] \[user\] \end{verbatim} Where \[flags\] are the passwd flags, read below for more info, the parameter \[user\] can only be @@ -2107,7 +2107,7 @@ Usage: The default tee command syntax is: \begin{verbatim} -tee [flags] [file] +tee \[flags\] \[file\] \end{verbatim} Where \texttt{\[flags\]} are the tee flags (below you will find more info), @@ -2149,7 +2149,7 @@ Usage The default cat command syntax is: \begin{verbatim} -cat [flags] [--] [file1] [file2] [file...] +cat \[flags\] \[--\] \[file1\] \[file2\] \[file...\] \end{verbatim} Where \[flags\] are the \texttt{cat} flags, read below for more info, \[--\] indacates that the @@ -2224,9 +2224,9 @@ You have to know also that "killall" sends SIGTERM, or signal number 15. If you want to specify a different signal you can use "-s". \begin{verbatim} -killall -s 9 [process name] -killall -KILL [process name] -killall -9 [process name] +killall -s 9 \[process name\] +killall -KILL \[process name\] +killall -9 \[process name\] \end{verbatim} kill @@ -2236,11 +2236,62 @@ Without options, kill sends SIGTERM to the PID specified and asks the applicatio or service to shut itself down. \begin{verbatim} -kill [PID] -kill -s KILL [PID] -kill -KILL [PID] +kill \[PID\] +kill -s KILL \[PID\] +kill -KILL \[PID\] \end{verbatim} +\section{chsh} + + +\large Joy Albertini \normalsize\\ + + + +The \texttt{chsh} command can be used to change the following user's login shell properties: + +\begin{itemize} + \item chenage Password of the user + \item shell local directory + \item Full name of the user + \item Office location + \item Office phone + \item home phone +\end{itemize} + +\begin{verbatim} +chsh \[-flag\] user +\end{verbatim} + +Flags + +\begin{itemize} + \item \textbf{-s}: set shell as the login shell + \item \textbf{-l}: change the symbolic link and not the file or directory referred + by the symbolic link. + + \item \textbf{-R}: change the ownership for each file in a folder, if encounter symbolic link + it will change the owenership of that symbolic link, + and the directory/file referred in the symbolic link, but the directory + is not further transversed. + + \item \textbf{-RH}: change the ownership for each file in a folder, if a symbolic link is + encountered, it will change the owenership of that symbolic link, + the directory/file referred in the symbolic link, and all the + directories are further transversed. + + \item \textbf{-RL}: if a symbolic link referencing a file of type directory + is specified on the command line or encountered during the traversal of a file hierarchy, + the chown command will change the user ID (and group ID, if specified) of the directory + referenced by the symbolic link and all files in the file hierarchy below it. + + \item \textbf{-RP}: changes the ownership for each file in a folder, if encounter symbolic link it + will change the owenership of that symbolic link, but will not change the + the directory/file referred in the symbolic link, and + the directory is not further transversed. + +\end{itemize} + \section{curl} @@ -2335,7 +2386,7 @@ Every process is an executing instance of a program which is assigned a unique P The basic syntax of \emph{ps} is: \begin{verbatim} -ps [options] +ps \[options\] \end{verbatim} @@ -2416,8 +2467,8 @@ To log in a remote server you need an user account which is usually created by the server admin and a password. \begin{verbatim} -localhost:[~]\textgreater ssh username@remote-server -remote-server:[~]\textgreater +localhost:\[~\]\textgreater ssh username@remote-server +remote-server:\[~\]\textgreater \end{verbatim} Once you're logged in, the local machine shell will be @@ -2434,7 +2485,7 @@ Log out of a server Run a command on a remote machine \begin{verbatim} -localhost:[~]:\textgreater ssh user@remote-host "ls test" +localhost:\[~\]:\textgreater ssh user@remote-host "ls test" online-backup.dat online-storage unix-dedicated-server.txt @@ -2446,15 +2497,15 @@ Debug the client Debugging the ssh client can be useful to resolve connection errors. \begin{verbatim} -localhost:[~]:\textgreater ssh -v user@remote-host - OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008 - debug1: Reading configuration data /etc/ssh/ssh_config +localhost:\[~\]:\textgreater ssh -v user@remote-host + OpenSSH\_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008 + debug1: Reading configuration data /etc/ssh/ssh\_config debug1: Applying options for * - debug1: Connecting to remote-host [172.22.200.140] port 22. + debug1: Connecting to remote-host \[172.22.200.140\] port 22. debug1: Connection established. debug1: identity file /home/user/.ssh/identity type -1 - debug1: identity file /home/user/.ssh/id_rsa type -1 - debug1: identity file /home/user/.ssh/id_dsa type 2 + debug1: identity file /home/user/.ssh/id\_rsa type -1 + debug1: identity file /home/user/.ssh/id\_dsa type 2 debug1: loaded 3 keys ... \end{verbatim} @@ -2859,7 +2910,7 @@ You can notice that the top lines in the window follow this structure: \begin{verbatim} Last login: Day Month hh:mm:ss on console -Device-name:~ username$ +Device-name:~ username\$ \end{verbatim} The tilde (~) just before your username means that the current position in @@ -2888,7 +2939,7 @@ Use chgrp \[:group\] file to create a group for a file \\ Use Sudo chown owner\[:group\], if you need root permission for add the user to the group \begin{verbatim} -chown user [group] file1 file2 ... +chown user \[group\] file1 file2 ... \end{verbatim} \begin{itemize} @@ -2935,8 +2986,8 @@ General syntax for both is: \begin{verbatim} -less [flags] path/name-file.* -more [flags] path/name-file.* +less \[flags\] path/name-file.* +more \[flags\] path/name-file.* \end{verbatim} @@ -3020,7 +3071,7 @@ The name stands for \emph{LiSt}. The default ls command syntax is: \begin{verbatim} -ls [flags] [path] +ls \[flags\] \[path\] \end{verbatim} Where \[flags\] are the ls flags, read below for more info,and \[path\] is the @@ -3062,7 +3113,7 @@ the displayed list using the \texttt{-a} flag. ls -a Photos . 01.png .. 02.png - .DS_Store 03.png + .DS\_Store 03.png .secret.png 04.jpg \end{verbatim} @@ -3133,7 +3184,7 @@ The \texttt{info} command allows you to read that kind of files and to search for particular information by using special flags. \begin{verbatim} -info [flag] [item] +info \[flag\] \[item\] \end{verbatim} Look up for a specific string @@ -3234,11 +3285,11 @@ you have to create the text files if they don't exist (with some text inside), to make the work. \begin{verbatim} -say -v Alex -f hello_world.txt +say -v Alex -f hello\_world.txt \end{verbatim} \begin{verbatim} -say -o hi.aac -f hello_world.txt +say -o hi.aac -f hello\_world.txt \end{verbatim} \section{ln} @@ -3267,9 +3318,9 @@ The symbolic link (symlink) instead contains the path to the original file and r will make the referencer point to the original file instead.\\ \begin{verbatim} -ln [flags] [source1] [source2] ... [target_dir] -ln [flags] [source] [target] -link [source] [target] +ln \[flags\] \[source1\] \[source2\] ... \[target\_dir\] +ln \[flags\] \[source\] \[target\] +link \[source\] \[target\] \end{verbatim} The \texttt{link} command can be used instead of \texttt{ln}, but flags and multiple @@ -3299,7 +3350,7 @@ The \texttt{du} command is used to display files and directories sizes.\\ The name stands for \emph{Disk Usage}. \begin{verbatim} -du [flags] [file1] [file2] [directory1] ... +du \[flags\] \[file1\] \[file2\] \[directory1\] ... \end{verbatim} Flags @@ -3366,7 +3417,7 @@ but with a different name.\\ It stands for \emph{MoVe}. \begin{verbatim} -mv [-finv] source target +mv \[-finv\] source target \end{verbatim} Flags @@ -3440,7 +3491,7 @@ If the permissions of the file do not permit writing, the user is prompted for c It stands for \emph{ReMove}. \begin{verbatim} -rm [-dfiPRrvW] file1 file2 file.... +rm \[-dfiPRrvW\] file1 file2 file.... \end{verbatim} Flags @@ -3519,7 +3570,7 @@ The name stands for \emph{MaKe DIRectory}.\\ The default ls command syntax is: \begin{verbatim} -mkdir [flags] [-m mode] directory_name ... +mkdir \[flags\] \[-m mode\] directory\_name ... \end{verbatim} Where \[flags\] are the mkdir \texttt{-p} and \texttt{-v} - flags, @@ -3532,9 +3583,9 @@ Let's see how to create a new directory: \begin{verbatim} ls -mkdir test_directory +mkdir test\_directory ls - test_directory + test\_directory \end{verbatim} Create a path of directories @@ -3542,7 +3593,7 @@ Using the flag \texttt{-p} we can create a path of directories, allowing us to build more than a directory at once. \begin{verbatim} -mkdir -p test_directory/subdir/subsubdir +mkdir -p test\_directory/subdir/subsubdir \end{verbatim} As you can see, we are now creating two directories: one named \emph{subdir} and @@ -3555,7 +3606,7 @@ The \texttt{-m mode} option allows us to set permissions at the new directory that we are now creating. \begin{verbatim} -mkdir -m 777 test_free_directory +mkdir -m 777 test\_free\_directory \end{verbatim} Our new directory will now have read,write and execute permissions for user, group and others. @@ -3571,7 +3622,7 @@ The \texttt{cp} command copies the contents of one or more files or directories target file or directory.\\ \begin{verbatim} -cp [source1] [source2] [source3] ... [target] +cp \[source1\] \[source2\] \[source3\] ... \[target\] \end{verbatim} @@ -3656,7 +3707,7 @@ The \texttt{touch} command updates the modification and access time of the a fil If the given file does not exists, it gets created.\\ \begin{verbatim} -touch [flags] [file1] [file2] ... +touch \[flags\] \[file1\] \[file2\] ... \end{verbatim} Flags @@ -3701,7 +3752,7 @@ The default cd command syntax is: \begin{verbatim} -cd [flags] [path] +cd \[flags\] \[path\] \end{verbatim} @@ -3744,7 +3795,7 @@ current working directory, you \underline{MUST} use the absolute path. output as input \\ -To redirect a certain output of the command-line we have to use the symbol "\textgreater ".\\ +To redirect the output of a command we use the symbol "\textgreater ".\\ In this case, we will use a file named \emph{hello.txt}, in which we want to insert a certain output ("Sun" in this case):\\ @@ -3775,10 +3826,10 @@ cat hello.txt input as output \\ -To redirect an input from a file for a command, the symbol "\textless " is used. +To redirect input from a file for a command, the symbol "\textless " is used. \begin{verbatim} -echo $lt; $(cat hello.txt) +echo \textless \$(cat hello.txt) Sun Moon \end{verbatim} @@ -3789,7 +3840,7 @@ This is particularly useful when chaining commands.\\ Chaining (or piping) Chaining, also called Piping because it works with the pipe symbol "|", takes -the output of a certain command-line and feeds it to another command in a direct way. +the output of a certain command and feeds it to another command. \begin{verbatim} cat hello.txt | grep Mo Moon @@ -3798,14 +3849,14 @@ Moon A simple example Now let's say that we want to combine those commands in a more complex operation. -Let's say we want to take some contents from a certain file and put it into another file.\\ +Let's say we want to take the content of a certain file and put it into another file.\\ We want to sort the animals whose name begins with letter "d" from the file \emph{animals.txt} and put it into \emph{d\_animals.txt}.\\ \begin{verbatim} -grep d \textless animals.txt \textgreater d_animals.txt - cat d_animals.txt +grep d \textless animals.txt \textgreater d\_animals.txt + cat d\_animals.txt Deer Dog Dolphin @@ -3821,23 +3872,23 @@ grep d \textless animals.txt \textgreater d_animals.txt Echo -This command print as output its entire argument on the command-line.\\ - It could be used with variables, like in the following example:\\ +This command prints its entire argument as output on the command-line.\\ + It can be used with variables, like in the following example:\\ \begin{verbatim} example="this is an example" -echo $example +echo \$example this is an example \end{verbatim} Cat -This command prints the content of a certain file as an output on the +This command prints the content of a certain file as output on the command-line.\\ -As example, we could imagine a simple text file in nano named "Hello", which contains +For example, we could imagine a simple text file in nano named "Hello", which contains the line "Hello World".\\ So, our command example will look like this:\\ @@ -3884,7 +3935,7 @@ that make them suitable for different needs while programming.\\ While loops take this form: \begin{verbatim} -while [condition] +while \[condition\] do command1 command2 @@ -3895,14 +3946,14 @@ done -Here is a first simple example: +Here is a simple first example: \begin{verbatim} i=0; -while [$i -lt 4] +while \[\$i -lt 4\] do - echo $i - i=$((i + 1)) + echo \$i + i=\$((i + 1)) done \end{verbatim} @@ -3931,21 +3982,21 @@ i=1; while : do - printf "i=$i\i: Hello World" - if [ $i == 3 ]; then + printf "i=\$i\i: Hello World" + if \[ \$i == 3 \]; then echo "I love DrRacket" - elif [ $i == 5]; then + elif \[ \$i == 5\]; then echo "I love Bash" - elif [ $i == 7 ]; then + elif \[ \$i == 7 \]; then echo "I love this website" - elif [ $i == 9 ]; then + elif \[ \$i == 9 \]; then exit 0 - i=$((i + 1)) + i=\$((i + 1)) done \end{verbatim} -No termination condition is set for this loop in this example. This type of loop -is called infinite loop.\\ +No termination condition is set for the loop in this example. This type of loop +is called an infinite loop.\\ The \texttt{ exit} statement is used to quit the loop. This loop will iterate for 9 times, then as soon as \texttt{ i} becomes equal to 0, the condition of the last if @@ -3983,10 +4034,10 @@ done In scripting, while loops are often used to process files line by line. \\ Here is an example: \begin{verbatim} -while read -r first_name last_name phone; +while read -r first\_name last\_name phone; do - printf '\%s\\n' "$last_name" -done \textless "$file" + printf '\%s\\n' "\$last\_name" +done \textless "\$file" \end{verbatim} The \texttt{ read } command is used to read a file line by line. @@ -4010,11 +4061,11 @@ This piece of code only prints out the second column. If statements allow us to make decisions in our Bash scripts. They allow us to -whether run or not a piece of code based on a condition that we set. \\ +decide whether or not to run a piece of code based on a condition that we set. \\ If statements take this form: \begin{verbatim} -if [condition]; then +if \[condition\]; then command1 command2 command3 @@ -4029,7 +4080,7 @@ Here is a simple example: \begin{verbatim} i=210; -if [$i -ge 200]; then +if \[\$i -ge 200\]; then echo "You chose a big number." fi \end{verbatim} @@ -4038,7 +4089,7 @@ In this first example we evaluate a variable \texttt{i} to 105. The \emph{ if statement } will print "You chose a big number" only if the number contained in our variable \texttt{i} is \textbf{G}reater or \textbf{E}qual to 200. \\ -This is our case, therefore the output of this piece of code will be: +This is the case, therefore the output of this piece of code will be: \begin{verbatim} You chose a big number. \end{verbatim} @@ -4051,9 +4102,9 @@ This is our case, therefore the output of this piece of code will be: Sometimes we want to perform a certain set of actions, if our condition evaluates to true and another set of actions if our condition evaluates to false. We can do this with the \emph{ if else } statement. -\emph{ if else } sattements take this form: +\emph{ if else } statements take this form: \begin{verbatim} -if [condition]; then +if \[condition\]; then command1 command2 command3 @@ -4070,17 +4121,17 @@ Here is a simple example: \begin{verbatim} i=50; -if [$i -ge 200]; then +if \[\$i -ge 200\]; then echo "You chose a big number." else echo "You chose a small number." fi \end{verbatim} -In this example, that is just an extension of the previous example, we +In this example, which is just an extension of the previous example, we evaluate a variable \texttt{i} to 50. If \texttt{i} is greater or equal to -200, you print out "You chose a big number", otherwise, -(if \texttt{i} is not greater or equal to 200), just like in this case, you print out +200, we print out "You chose a big number", otherwise, +(if \texttt{i} is not greater or equal to 200), just like in this case, we print out "You chose a small number". Therefore, the output of this piece of code is: @@ -4097,12 +4148,12 @@ different paths. We can accommodate this need with the \emph{if else elif} mecha The \emph{if else elif} mechanism takes this form: \begin{verbatim} -if [condition]; then +if \[condition\]; then command1 command2 command3 ... -elif [condition]; then +elif \[condition\]; then command1 command2 command3 @@ -4120,16 +4171,16 @@ Here is a simple example: \begin{verbatim} i=150; -if [$i -ge 200]; then +if \[\$i -ge 200\]; then echo "You chose a big number." -elif [$i == 150]; then +elif \[\$i == 150\]; then echo "You chose 150". else echo "You chose a small number" fi \end{verbatim} -In this example, that is just an extension of the previous example, we evaluate a +In this example, which is just an extension of the previous example, we evaluate a variable \texttt{i} to 150. If \texttt{i} is greater or equal to 200, you print out "You chose a big number", if \texttt{i} is equal to 150 you print out "You chose 150" otherwise you print out "You chose a small number". @@ -4150,8 +4201,8 @@ Therefore, the output of this piece of code is: The second type of loops are for loops. They follow this syntax: \begin{verbatim} - for [variable] in [list] do - [code] + for \[variable\] in \[list\] do + \[code\] done \end{verbatim} @@ -4177,7 +4228,7 @@ Here is a simple example: \begin{verbatim} for i in 1 2 3 4 5 do - echo "Welcome $i times" + echo "Welcome \$i times" done \end{verbatim} @@ -4197,8 +4248,8 @@ There are also other ways to specify the \emph{ numerical range }. For instance, your numerical range is too big, you can simply write: \texttt{ {1..100} }. This piece of code means every natural number between 1 and 100 (both included). \\ Ranges can also count backward like this: \texttt{{10..1}}. -You can even increment the numerical value by step of two: \texttt{ {0..10..2} }. -This piece of code means every natural number between 0 and 10 with a step of two, +You can even increment the numerical value by steps of two: \texttt{ {0..10..2} }. +This piece of code means every natural number between 0 and 10 in steps of two; 0 2 4 6... 10. @@ -4210,39 +4261,39 @@ This piece of code means every natural number between 0 and 10 with a step of tw A variable is simply a string to which we assign a certain type of data, -which could be a text, a number, a filename and other types of data.\\ +which could be some text, a number, a filename or other types of data.\\ Naming a variable -To name a variable in Unix we have to use only letters, numbers or +To name a variable in Unix we can only use letters, numbers or the underscore character (\_).\\ Other characters can't be used because they have a special meaning in Unix Shell.\\ Some simple examples are: \begin{verbatim} -VAR_1 -VAR_2 -NAME_3 -name_4 +VAR\_1 +VAR\_2 +NAME\_3 +name\_4 \end{verbatim} Defining a variable -To define a certain variable, we could use the following basecase: +To define a certain variable, we use the following base case: \begin{verbatim} -variable_name=variable_value +variable\_name=variable\_value \end{verbatim} Let me show you a simple example: \begin{verbatim} -VAR_1=Strawberry +VAR\_1=Strawberry \end{verbatim} @@ -4250,48 +4301,48 @@ To access a variable we have to use the dollar sign (\$). So if I want to access VAR\_1, I have to write: \begin{verbatim} -VAR_1="Strawberry" -echo $VAR_1 +VAR\_1="Strawberry" +echo \$VAR\_1 Strawberry \end{verbatim} Deleting a variable -Deleting a variable means that shell will remove a certain variable from the list of +Deleting a variable means that the shell will remove a certain variable from the list of those that it tracks.\\ To delete a variable we use the following command: \begin{verbatim} -unset variable_name +unset variable\_name \end{verbatim} which in our case would be: \begin{verbatim} -unset VAR_1 +unset VAR\_1 \end{verbatim} Protecting variables -To protect a certain variable, we can set them as read-only so that it can't be +To protect a certain variable, we can set it as read-only so that it can't be changed or deleted.\\ So, if we try to change the value of VAR\_1, the result will be the following: \begin{verbatim} -VAR_1="Strawberry" -readonly VAR_1 -VAR_1="Blueberry" - VAR_1: This variable is read only. +VAR\_1="Strawberry" +readonly VAR\_1 +VAR\_1="Blueberry" + VAR\_1: This variable is read only. \end{verbatim} -If we try to delete the variable, shell will give us the following value: +If we try to delete the variable, the shell will give us the following error: \begin{verbatim} -VAR_1="Strawberry" -unset VAR_1 - VAR_1: This variable is read only. +VAR\_1="Strawberry" +unset VAR\_1 + VAR\_1: This variable is read only. \end{verbatim} \section{Parameter expansion} @@ -4306,14 +4357,14 @@ There are some special operations that can be performed on The general syntax for all parameter expansions is this one: \begin{verbatim} - ${CODE_HERE} + \${CODE\_HERE} \end{verbatim} Depending on what you want to do with your variable, the code that goes inside the braces differs.\\ \begin{verbatim} - ${VARIABLE:-DEFAULT_VALUE} + \${VARIABLE:-DEFAULT\_VALUE} \end{verbatim} If the variable VARIABLE exists and has a value (i.e. it is not null), this is equal to @@ -4323,7 +4374,7 @@ Otherwise, it is equal to DEFAULT\_VALUE.\\ Example: \texttt{echo "First name: \${firstname:-John}";}\\ \begin{verbatim} - ${VARIABLE:=DEFAULT_VALUE} + \${VARIABLE:=DEFAULT\_VALUE} \end{verbatim} If the variable VARIABLE exists and has a value, this is equal to the value of VARIABLE. @@ -4331,7 +4382,7 @@ Otherwise, it sets the variable to DEFAULT\_VALUE and is equal to it.\\ Example: \texttt{echo "Last name: \${lastname:=Doe}";}\\ \begin{verbatim} - ${VARIABLE:?ERR_VALUE} + \${VARIABLE:?ERR\_VALUE} \end{verbatim} If the variable VARIABLE exists and has a value, this is equal to the value of VARIABLE. @@ -4340,7 +4391,7 @@ after this).\\ Example: \texttt{currdate=\${date:?Operation failed: date unknown};}\\ \begin{verbatim} - ${VARIABLE:+VALUE} + \${VARIABLE:+VALUE} \end{verbatim} If the variable VARIABLE exists and has a value, this is equal to VALUE. @@ -4352,7 +4403,7 @@ All of these can also be written without the colon, in which case their meaning "If the variable VARIABLE exists at all (even if it is null), this is ..."\\ \begin{verbatim} - ${VARIABLE: NUMBER} + \${VARIABLE: NUMBER} \end{verbatim} This is equal to the substring of the value of VARIABLE, starting at the character with @@ -4361,7 +4412,7 @@ If NUMBER is negative, the substring starts NUMBER characters before the end of Example: \texttt{lastname=\${fullname:\$firstnamelength};}\\ \begin{verbatim} - ${VARIABLE: FROM:LENGTH} + \${VARIABLE: FROM:LENGTH} \end{verbatim} This is equal to the substring of the value of VARIABLE, starting at the character with (0-based) @@ -4370,7 +4421,7 @@ If FROM is negative, the substring starts FROM characters before the end of the Example: \texttt{lastname=\${middlename:\$firstnamelength:\$middlenamelength};}\\ \begin{verbatim} - ${#VARIABLE} + \${\#VARIABLE} \end{verbatim} This is equal to the length of the value of VARIABLE\\ @@ -4379,7 +4430,7 @@ Example: \texttt{echo "your name has \${\#name} characters";}\\ Paremeter expansions can also be nested, like this: \begin{verbatim} - ${input:?${INVALID_INPUT_ERR_MSG:-An unknown error occurred}} + \${input:?\${INVALID\_INPUT\_ERR\_MSG:-An unknown error occurred}} \end{verbatim} Further reading: @@ -4392,20 +4443,20 @@ the bash reference manual -There are certain strings that we can not use in the variable-naming process.\\ -In this page we will see what actually are those strings, and what's their purpose.\\ +There are certain strings that we can't use in the variable-naming process.\\ +In this page we will see what those strings are, and what their purpose is.\\ \$\$ -To begin, we will see the simplest variable, which is the dollar sign (\$). -This command simply gives us the process ID number of the current shell.\\ +To begin, we look at the simplest variable, which is the dollar sign (\$). +This command simply gives us the process ID of the current shell.\\ \begin{verbatim} -echo $$ +echo \$\$ 11480 \end{verbatim} \$0 -This variable will simply give us the filename of the current script. +This variable simply gives us the filename of the current script. \$n This variable corresponds to the arguments with which a script was invoked. @@ -4415,7 +4466,7 @@ Here n is a positive number corresponding to the position of an argument. This variable gives us the number of arguments supplied to a script. \$! -This variable gives us the process number of the last background command. +This variable gives us the process ID of the last background command. \section{Arrays} @@ -4437,7 +4488,7 @@ This will create an array, called \texttt{names}, which holds 4 values. The values in the array can be accessed using the syntax \begin{verbatim} - ${names[SELECTOR]} + \${names\[SELECTOR\]} \end{verbatim} where SELECTOR is the selector associated to the desired element. There are two kinds of @@ -4454,7 +4505,7 @@ If we want to specify a particular index for our values when creating the array we can do it like this: \begin{verbatim} - names=([1]="Anna" [2]="Bob" [5]="Ernie" [12]="Luigi") + names=(\[1\]="Anna" \[2\]="Bob" \[5\]="Ernie" \[12\]="Luigi") \end{verbatim} As you might have guessed, this will create an array with \texttt{"Anna"} at index 1, @@ -4463,7 +4514,7 @@ As you might have guessed, this will create an array with \texttt{"Anna"} at ind If our indices are all sequential and we just want to change the starting index, we can use \begin{verbatim} - names=([12]="Luigi" "Mario" "Nate") + names=(\[12\]="Luigi" "Mario" "Nate") \end{verbatim} Which will create an array with \emph{"Luigi"} at index 12, @@ -4478,7 +4529,7 @@ In an associative array, the values are not mapped to a number but to some other Here's an example of an associative array: \begin{verbatim} - colors=([white]="#FFFFFF" [black]="#000000" [red]="#FF0000" [yellow]="#00FFFF") + colors=(\[white\]="\#FFFFFF" \[black\]="\#000000" \[red\]="\#FF0000" \[yellow\]="\#00FFFF") \end{verbatim} In this case it is not possible to omit the selector as there is no logical word @@ -4487,13 +4538,13 @@ instead of a number as the selector.\\ Arrays, both kinds, can also be modified after creation. We can use \begin{verbatim} - colors[blue]="#0000FF" + colors\[blue\]="\#0000FF" \end{verbatim} to add an element to the array (or modify it if it exists already) and \begin{verbatim} - unset colors[black] + unset colors\[black\] \end{verbatim} to remove one.\\ @@ -4508,13 +4559,13 @@ much like it works on strings, but it manipulates the members of the array inste For example: \begin{verbatim} - ${names[@]: 13} + \${names\[@\]: 13} \end{verbatim} is equivalent to \texttt{"Mario" "Luigi"}, while \begin{verbatim} - ${#names[@]} + \${\#names\[@\]} \end{verbatim} counts the number of elements in the array, in this case 3.\\ diff --git a/site/pages/cmd/interm/chroot.html b/site/pages/cmd/interm/chroot.html index 18c5db0..3844ed7 100644 --- a/site/pages/cmd/interm/chroot.html +++ b/site/pages/cmd/interm/chroot.html @@ -6,7 +6,7 @@ tags: change root author: Gianmarco De Vita title: chroot previous-page: pages/cmd/interm/cat.html -next-page: pages/cmd/interm/curl.html +next-page: pages/cmd/interm/chsh.html --- The chroot utility allows you to change its root directory to the one indicated in newroot and, if given, executes the command.
diff --git a/site/pages/cmd/interm/chsh.html b/site/pages/cmd/interm/chsh.html index d55b1d8..bfb31af 100644 --- a/site/pages/cmd/interm/chsh.html +++ b/site/pages/cmd/interm/chsh.html @@ -1,38 +1,54 @@ --- layout: page category-page: intermediate -category-title: intermediate commands +category-title: Intermediate commands author: Joy Albertini -tags:directory user shell +tags: directory user shell title: chsh +previous-page: pages/cmd/interm/chroot.html +next-page: pages/cmd/interm/curl.html --- -

The chsh -command cheanges user's login shell property: +The chsh command can be used to change the following user's login shell properties: +