diff --git a/docs/website_as_latex/2018-11-18_08-50.tex b/docs/website_as_latex/2018-11-18_11-45.tex similarity index 97% rename from docs/website_as_latex/2018-11-18_08-50.tex rename to docs/website_as_latex/2018-11-18_11-45.tex index 095a496..91c7a45 100644 --- a/docs/website_as_latex/2018-11-18_08-50.tex +++ b/docs/website_as_latex/2018-11-18_11-45.tex @@ -1,4 +1,4 @@ -% File autogenerated using the Bonus 2 program at 2018-11-18 08:50 +% File autogenerated using the Bonus 2 program at 2018-11-18 11:45 \documentclass[hidelinks,12pt,a4paper,numbers=enddot]{scrartcl} \usepackage[margin=2cm]{geometry} @@ -86,35 +86,52 @@ Prints the word count. \large Alessandro Luini \normalsize\\ + + The default editor that comes with the UNIX operating system is called \texttt{vi} (visual editor).\\ The UNIX vi editor is a full screen editor and has two modes of operation: + \begin{itemize} \item Command mode commands which cause action to be taken on the file \item Insert mode in which entered text is inserted into the file. \end{itemize} + + In the command mode, every character typed is a command that does something to the text file being edited; a character typed in the -command mode may even cause the vi editor to enter the insert mode.\\ +command mode may even cause the vi editor to enter the insert mode. + + + In the insert mode, every character typed is added to the text in the -file; pressing the {Esc} (Escape) key turns off the Insert mode.\\ +file; pressing the {Esc} (Escape) key turns off the Insert mode. + + + While there are a number of vi commands, just a handful of these is usually sufficient for beginning vi users. To assist such users, this Web page contains a sampling of basic vi commands. The most basic and useful commands are marked with an asterisk (* or star) in the tables below. With practice, these commands should become -automatic.\\ +automatic. + + + Both UNIX and vi are \textbf{case-sensitive}. Be sure not to use a capital letter in place of a lowercase letter; the -results will not be what you expect.\\ +results will not be what you expect. + How to start \texttt{vi} + + To use vi on a file, type in vi filename. If the file named filename exists, then the first page (or screen) of the file will be displayed; if the file does not exist, then an empty @@ -340,13 +357,6 @@ in a Linux system and use it for basic text editing. Emacs is also available for graphical window managers, however we will only cover the "text based" version here. -How to install - -Run the following command: -\begin{verbatim} -install emacs -\end{verbatim} - Open a file, or create it like this: \begin{verbatim} @@ -1146,6 +1156,8 @@ Managing modification + + The \texttt{ping} command, is used to test connection between a \textbf{local server/computer} to a \textbf{remote UNIX server}.\\ The ping command sends \textbf{ICMP Echo Request packets} to the remote server for accessing it. @@ -1355,7 +1367,7 @@ number, line breaks are added every specified "number" characters. base64 -b number path/input.file path/output.file \end{verbatim} -By leaving the number field empty, an unbroken stream will be generated.< +By leaving the number field empty, an unbroken stream will be generated. Decode Base64 Using the \texttt{-D} flag (which stands for decode), you obtain as @@ -1373,6 +1385,35 @@ in which are listed the flags with the respective paragraph will be displayed. base64 -h \end{verbatim} +\section{caffeinate} + + +\large Joao Tomazoni \normalsize\\ + + + +The \texttt{caffeinate} command prevents the computer to go into sleep mode, +just as if you would set it to never sleep in the system preferences. +Type \texttt{caffeinate -d} in your terminal and it will prevent your screen to sleep +without changing the system preferences. + +\begin{verbatim} +caffeinate -d +\end{verbatim} + +You can also prevent your computer to go sleep while another process is taking place, but turn sleep +mode on again when the process is over, for that you use the same code as above, and then type the +arguments you want to run and prevent computer to go on sleep mode. For example, say you have a +big file on your desktop that you want to md5, and you want to prevent your computer to enter +the sleep mode: + +\begin{verbatim} +caffeinate -d ~/Desktop/bigfile +\end{verbatim} + +Doing so, your computer is now prevent to enter on sleep mode while the md5 process is running, +and automatically turn the sleep mode on again when the process is completed. + \section{chroot} @@ -1609,12 +1650,17 @@ This specifies you want to extract an archive instead of creating one. + + The strings command returns each string of printable characters (ASCII) in files. Its main uses are to determine the contents of and to extract text from binary files (i.e., non-text files). From the Shell manual: "find the -printable strings in a object, or other binary, file".\\ +printable strings in a object, or other binary, file". -Strings can be used to extract character information and string of a given lenght + + + +Strings can be used to extract character information and string of a given length from text file(s). When used without any options, strings displays all strings that are at least four characters in length in the files whose names are supplied as arguments (i.e., input data). Strings that are on separate lines @@ -1622,13 +1668,15 @@ in the input files are shown on separate lines on the screen, and an attempt is made to display all strings found on a single line in a file on a single line on the screen (although there may be a carryover to subsequent lines in the event that numerous strings are found on a single line). strings looks in -all sections of the object files except the (\_\_TEXT,\_\_text) section.\\ +all sections of the object files except the (\_\_TEXT,\_\_text) section. + \begin{verbatim} strings \[options\] file\_name(s) \end{verbatim} - Flags +Flags + \begin{itemize} \item -n: Specify the minimum string length, where the number argument is a positive decimal integer. The default is 4. @@ -1689,23 +1737,31 @@ Flags \large Claudio Maggioni \normalsize\\ + + The \texttt{pass} command, also known as \emph{Password Store}, is an entirely offline password manager that uses \emph{GPG} for encryption with the ability to sync the (entirely encrypted) passwords using \texttt{git}. \texttt{pass} works on \emph{MacOS} (avaliable via \underline{\href{https://brew.sh}{Homebrew}}), \emph{Linux} and on \emph{Android} (with a GUI app). Think of it as an entirely FLOSS -alternative to services like \emph{Keypass} or \emph{Dashlane}.\\ +alternative to services like \emph{Keypass} or \emph{Dashlane}. + + + Excluding the initial setup (that requires the creation of a \emph{GPG key}), \texttt{pass} is very easy and straightforward to use: instead of printing passwords to \emph{stdout}, \texttt{pass} copies them in the system clipboard, erasing them after a certain number of seconds (usually -\emph{45}).\\ +\emph{45}). + + + \texttt{pass} has many unofficial GUI clients and migration scripts from other password managers. For more information, check out -the official website. +\underline{\href{https://www.passwordstore.org/\#other}{the official website}}. Setup @@ -1717,7 +1773,10 @@ to some other useful sets of commands (such as how to migrate the password repository to another computer) is provided in this GitHub Gist by -\emph{flbuddymooreiv}.\\ +\emph{flbuddymooreiv}. + + + For more detailed explainations on the setup process or on any commands please check out the online version of the @@ -1730,58 +1789,83 @@ Usage Common \texttt{pass} commands are shown below. For more information refer -to the documentation linked above.\\ +to the documentation linked above. + + +\textbf{ Example: Initialize the password repository with a GPG key with id "0DEADBEEF" +} \begin{verbatim} pass init 0DEADBEEF \end{verbatim} + +\textbf{ Example: Insert a password for \emph{example.com} with username \emph{bob} in the password repository interactively +} \begin{verbatim} pass insert example.com/bob \end{verbatim} + + Please note that the password \emph{name} here follows the most common naming convention in \texttt{pass}, which is \texttt{{website}/{username}}. Passwords can be stored in hierarchical structures (i.e. in nested folders), but the naming is up to the -user.\\ +user. + + +\textbf{ Example: Generate a password for \emph{zombo.com} of 16 characters and copy it in the clipboard +} \begin{verbatim} pass generate -c zombo.com/bob 16 \end{verbatim} + +\textbf{ Example: Retrieve the password for \emph{google.com} and copy it in the system clipboard (\texttt{-c} flag) +} \begin{verbatim} pass -c google.com/bob@gmail.com \end{verbatim} + +\textbf{ Example: Edit the password for \emph{facebook.com} using the default editor +} \begin{verbatim} pass edit facebook.com/bob \end{verbatim} + +\textbf{ Edit: Convert the password repository to a git repository for synchronization +} \begin{verbatim} pass git init \end{verbatim} + + Every \texttt{git} command on the password repository must be given with the prefix \texttt{pass git} (e.g. \texttt{pass git push}). An automatic commit is performed whenever a password is created, edited or deleted. + \section{fg} @@ -1882,16 +1966,50 @@ Here are some of the most common passwd flags: + The \texttt{sync} utility force the completion of pending disk writes. \begin{verbatim} sync \end{verbatim} + + This command can be used to verify that there are no pending disk writes, so that all the operations are completed, before the processor is stopped by other commands. + +\section{htop} + + +\large Joao Tomazoni \normalsize\\ + + + +The \texttt{htop} command is used to display the system resources +usage and the active processes. +You can use it to see how your computer is running and what's using the +RAM and the CPU. + +\begin{verbatim} +htop +\end{verbatim} + +To quit \texttt{htop} you need to type \texttt{q} on your keyboard. You can also click +with the mouse or touchpad to sort the columns of the displayed data.\\ +You can move across the stats using the keys on your keyboard. + +Flags + +\begin{itemize} + \item \textbf{-d}: set the delay of refresh of information + \item \textbf{-C}: disable colors + \item \textbf{-p}: display only a specified process id + \item \textbf{-u}: display only a specified user + \item \textbf{-t}: display the processes with a tree view so you can understand better +\end{itemize} + \section{mount} @@ -2044,6 +2162,8 @@ Here are some of the most common cat flags: + + Neofetch is a fast, higly customizable system info script. a CLI system information tool written in BASH. Neofetch displays information about your system next to an image, your OS logo, or any ASCII file of your choice. @@ -2100,7 +2220,7 @@ killall -9 \[process name\] kill Will terminate only one program. -Without Without options, kill sends SIGTERM to the PID specified and asks the application +Without options, kill sends SIGTERM to the PID specified and asks the application or service to shut itself down. \begin{verbatim} @@ -2364,168 +2484,6 @@ Here are just some of the most useful options for this command: \end{itemize} -\section{Open the Shell} - - -\large Gianmarco De Vita \normalsize\\ - - - -The tool that allows us to interact with the system with the shell is the terminal. -There are mainly two ways to access to the terminal on a MacOS system. - -Through the Finder - -\begin{itemize} - \item Open a new \emph{Finder} window by clicking on the icon on the system dock. - - \item On the menu bar, click on \emph{Go}. - - \item Click on \emph{Utilities}. - - \item Look for \emph{Terminal} and click on it. - -\end{itemize} - -Through \emph{Spotlight} -\begin{itemize} - \item You can use the shortcut \texttt{cmd+space} to access to \emph{Spotlight}. - - \item Then search for \emph{Terminal}. - - \item Click on the \emph{Terminal} icon displayed as result. - -\end{itemize} - -As you open the Terminal, a new blank window opens: - - - -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\$ -\end{verbatim} - -The tilde (~) just before your username means that the current position in -which the terminal is working is the Home directory. The gray spot next to -the symbol \$ after your username indicates that you can write instructions -in that space.\\ - -Now, you are ready to try and use some simple commands -to familiarize with this interface.\\ - -Note that you can work simultaneously on multiple sessions of the Terminal. - -\section{chown} - - -\large Joy Albertini \normalsize\\ - - - - -The \texttt{chown} -If you want to change the user ID of a specific file, you can use chown. \\ -Device-name:Current-position username\$ chown owner\[:group\] file \\ -Example chown Joy:student alice.txt add Joy to the group student \\ -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 ... -\end{verbatim} - -\begin{itemize} - \item \textbf{-f} Don't show all error messages except usage messages. - \item \textbf{-h} Changes the symbolic link and not the file or directory referred - by the symbolic link. - - \item \textbf{-R} changing the ownership for each file in a folder, if it encounters - a symbolic link it will cheange the owenership of that symbolic link, - and the directoryfile referred in the symbolic link, but the directory is not - further transversed. - - \item \textbf{-RH} changing the ownership for each file in a folder, if encounter symbolic link - it will change the owenership of that symbolic link, - the directory/file referred in the symbolic link, and all the - directory is further transversed. - - \item \textbf{-RL} If the -R option is specified and 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 shall 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} changing the ownership for each file in a folder, if encounter symbolic - link it will cheange the owenership of that symbolic link, but will not chenage the - the directory/file referred in the symbolic link, and the directory is not - further transversed. - -\end{itemize} - -\section{info} - - -\large Gianmarco De Vita \normalsize\\ - - -An \emph{.info} file is an information document created by Texinfo.\\ -It stores documentation in a book format with chapters, sections, -and subsections and can contain up to four layers of depth.\\ -Info documents are used for storing software help manuals and technical books.\\ -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\] -\end{verbatim} - -Look up for a specific string - -Using the \texttt{--apropos} flag followed by a string, you obtain as -output a list of all the contents which correspond to the string you wrote. - -\begin{verbatim} -info --apropos string -\end{verbatim} - -If the string you inserted has nothing to do with the content of the info files, -you will get a error message. For example: - -\begin{verbatim} -info --apropos duck - info: No available info files have `duck' in their indices. -\end{verbatim} - -An help with this command -Using the \texttt{-h} flag (which stands for help), you obtain as -output a brief paragraph in which are explained the features of this command.\\ - -Visit a specific \emph{.info} file - -Using the \texttt{-f} flag followed by the path and a \emph{.info} file, you -as output obtain the content of that file. - -\begin{verbatim} -info -f path/filename.info -\end{verbatim} - -\section{whatis} - - -\large Marzio Lunghi \normalsize\\ - - - -The \texttt{whatis} command gives you a brief description of a command. - -\begin{verbatim} -whatis command -\end{verbatim} - -It's similar to \texttt{man -f command} - \section{Closing the shell} @@ -2544,12 +2502,80 @@ If you want to close the shell session, there are several ways to do so: \end{itemize} +\section{open} + + +\large Gianmarco De Vita \normalsize\\ + + + +You can open files and folder as new windows through the terminal. +The command is \texttt{open}. By writing the command open followed by the +path and the name of the file (remember that you can omit the path if +the file is in the current position), a new window in the common user +interface opens. Now you can work on the opened file. + +\begin{verbatim} +open path/name-file +\end{verbatim} + +Open a file with a specific application +Adding the flag \texttt{-a} to the command permit you to decide with +which specific application open the file. Just write the flag followed by the +name of the application. + +\begin{verbatim} +open -a application-name path/name-file +\end{verbatim} + +Assume that you want to open the file \emph{abc.pdf} on my Desktop using the program "preview". + +\begin{verbatim} +open -a preview Desktop/abc.pdf +\end{verbatim} + +As result, a new \emph{Preview} window appears showing the content of the +chosen file.\\ + +Open the folder which contains the file +If you want to open the folder that contains a specific file, just use +the flag \texttt{-R} and write the path and the name of the file you want to open. + +\begin{verbatim} +open -R Desktop/text.txt +\end{verbatim} + +As result, a new \emph{Finder} window opens the folder displaying its content.\\ + +Open a file with an editor +If you want to open a file with your default editor, +just use the flag \texttt{-t} and write the path and the name of +the file you want to open. + +\begin{verbatim} +open -t Desktop/text.txt +\end{verbatim} + +Visit a Website +You can use this tool not only to open files and folders, but also webpages. +Just write the command \texttt{open} followed by the \emph{URL} of the page +you want to visit. + +\begin{verbatim} +open http://www.google.com +\end{verbatim} + +A new page of your default browser will open on the indicated page (in this +example, the main page of the Google Search Engine). + \section{man} \large Gianmarco De Vita \normalsize\\ + + The \texttt{man} tool allows you to explore the various utilities of the Shell. To search for more information about a command, just write @@ -2557,11 +2583,14 @@ of the Shell. To search for more information about a command, just write man command-name \end{verbatim} + + As result, a new session will be opened with information about the command you have typed (and more specifically about its functions and flags).\\ Using some flags, you can obtain with this command the same results you get -when you use other commands.\\ +when you use other commands. + Flags @@ -2599,102 +2628,6 @@ With mv you can rename a file: Device-name:Current-position username\$ mv path/n Example: desktop as working directory there is a file called name2.txt, mv-f name1.txt name2.txt will overwrite the file without prompting \end{itemize} -\section{ls} - - -\large Alessandro Marinelli \normalsize\\ - - -The \texttt{ls} command is used to list a directory content or a file.\\ -The name stands for \emph{LiSt}. - -The default ls command syntax is: - -\begin{verbatim} -ls \[flags\] \[path\] -\end{verbatim} - -Where \[flags\] are the ls flags, read below for more info,and \[path\] is the -(optional) path (absolute or relative).If no path is provided the current -directory is listed.\\ - -Usage - -List the elements on the current working directory -Let's see how to show a list containing the elements included in the -current working directory - -\begin{verbatim} -ls - Other Multimedia my-cat.jpg - Photos Videos -\end{verbatim} - -As you can see, typing \texttt{ls} in the Unix Shell, will give as output -the list of elements contained in the current working directory.\\ -Elements listed can be files (look for exemple at the element\emph{my-cat.jpg}), -such as other directories (look for example at the folder \emph{Photos}).\\ - -List the elements contained in a directory -\begin{verbatim} -ls Photos - 01.jpg 02.jpg - 03.jpg 04.jpg -\end{verbatim} - -As you can see, now the Unix Shell is showing us the elements contained -in the folder \emph{Photos}.\\ - -Show hidden files -You can include hidden files (those which name starts with ".") in -the displayed list using the \texttt{-a} flag. - -\begin{verbatim} -ls -a Photos - . 01.png - .. 02.png - .DS\_Store 03.png - .secret.png 04.jpg -\end{verbatim} - -As you can see, now the shell shows more files for the same directory.\\ - -Show list in long format - -\begin{verbatim} -ls -l - total 10816 - -rw-r--r--@ 1 YourName YourGroup 3143706 4 Ott 13:28 01.png - -rw-r--r--@ 1 YourName YourGroup 2269193 28 Ott 18:58 02.png - -rw-r--r--@ 1 YourName YourGroup 37900 28 Ott 22:07 03.png - -rw-r--r--@ 1 YourName YourGroup 75924 20 Ott 16:01 04.jpg -\end{verbatim} - -If the \texttt{-l} flag is given, the following information will be displayed for -each file: file mode, number of links, owner name, group name, number of -bytes in the file, abbreviated month, day-of-month file was last modified, -hour file last modified, minute file last modified, and the path. - -In addition, for each directory whose contents are displayed, the -total number of 512-byte blocks used by the files in the directory is -displayed on a line by itself, immediately before the information for the -files in the directory. - -\section{clear} - - -\large Marzio Lunghi \normalsize\\ - - -If you want to clear the shell screen up to the start you have to digit -the \texttt{clear} command: - -\begin{verbatim} -clear -\end{verbatim} - -This command corresponds to the \texttt{ ⌘ + K } key combination on Mac OS - \section{MacOS terminal toolbar} @@ -2744,7 +2677,7 @@ Shell - \begin{itemize} +\begin{itemize} \item \textbf{New Window}: It creates a new window. \item \textbf{New Tab}: It creates a new tab \item \textbf{Close window}: This option closes the window without quitting the terminal. @@ -2770,7 +2703,7 @@ Shell The text must be selected by holding down the touchpad and then moving the mouse cursor. \item \textbf{Print}: This options prints all the content of the shell. - \end{itemize} +\end{itemize} Edit @@ -2875,98 +2808,139 @@ Help \end{itemize} -\section{open} +\section{Open the Shell} \large Gianmarco De Vita \normalsize\\ -You can open files and folder as new windows through the terminal. -The command is \texttt{open}. By writing the command open followed by the -path and the name of the file (remember that you can omit the path if -the file is in the current position), a new window in the common user -interface opens. Now you can work on the opened file. +The tool that allows us to interact with the system with the shell is the terminal. +There are mainly two ways to access to the terminal on a MacOS system. + +Through the Finder + + + +\begin{itemize} + \item Open a new \emph{Finder} window by clicking on the icon on the system dock. + \item On the menu bar, click on \emph{Go}. + \item Click on \emph{Utilities}. + \item Look for \emph{Terminal} and click on it. +\end{itemize} + + + +Through \emph{Spotlight} +\begin{itemize} + \item You can use the shortcut \texttt{cmd+space} to access to \emph{Spotlight}. + \item Then search for \emph{Terminal}. + \item Click on the \emph{Terminal} icon displayed as result. +\end{itemize} + + + +The terminal + +As you open the Terminal, a new blank window opens:\\ +You can notice that the top lines in the window follow this structure: \begin{verbatim} -open path/name-file +Last login: Day Month hh:mm:ss on console +Device-name:~ username\$ \end{verbatim} -Open a file with a specific application -Adding the flag \texttt{-a} to the command permit you to decide with -which specific application open the file. Just write the flag followed by the -name of the application. +The tilde (~) just before your username means that the current position in +which the terminal is working is the Home directory. The gray spot next to +the symbol \$ after your username indicates that you can write instructions +in that space.\\ + +Now, you are ready to try and use some simple commands +to familiarize with this interface.\\ + +Note that you can work simultaneously on multiple sessions of the Terminal. + +\section{chown} + + +\large Joy Albertini \normalsize\\ + + + + +The \texttt{chown} +If you want to change the user ID of a specific file, you can use chown. \\ +Device-name:Current-position username\$ chown owner\[:group\] file \\ +Example chown Joy:student alice.txt add Joy to the group student \\ +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} -open -a application-name path/name-file +chown user \[group\] file1 file2 ... \end{verbatim} -Assume that you want to open the file \emph{abc.pdf} on my Desktop using the program "preview". +\begin{itemize} + \item \textbf{-f} Don't show all error messages except usage messages. + \item \textbf{-h} Changes the symbolic link and not the file or directory referred + by the symbolic link. + + \item \textbf{-R} changing the ownership for each file in a folder, if it encounters + a symbolic link it will cheange the owenership of that symbolic link, + and the directoryfile referred in the symbolic link, but the directory is not + further transversed. + + \item \textbf{-RH} changing the ownership for each file in a folder, if encounter symbolic link + it will change the owenership of that symbolic link, + the directory/file referred in the symbolic link, and all the + directory is further transversed. + + \item \textbf{-RL} If the -R option is specified and 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 shall 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} changing the ownership for each file in a folder, if encounter symbolic + link it will cheange the owenership of that symbolic link, but will not chenage the + the directory/file referred in the symbolic link, and the directory is not + further transversed. + +\end{itemize} -\begin{verbatim} -open -a preview Desktop/abc.pdf -\end{verbatim} - -As result, a new \emph{Preview} window appears showing the content of the -chosen file.\\ - -Open the folder which contains the file -If you want to open the folder that contains a specific file, just use -the flag \texttt{-R} and write the path and the name of the file you want to open. - -\begin{verbatim} -open -R Desktop/text.txt -\end{verbatim} - -As result, a new \emph{Finder} window opens the folder displaying its content.\\ - -Open a file with an editor -If you want to open a file with your default editor, -just use the flag \texttt{-t} and write the path and the name of -the file you want to open. - -\begin{verbatim} -open -t Desktop/text.txt -\end{verbatim} - -Visit a Website -You can use this tool not only to open files and folders, but also webpages. -Just write the command \texttt{open} followed by the \emph{URL} of the page -you want to visit. - -\begin{verbatim} -open http://www.google.com -\end{verbatim} - -A new page of your default browser will open on the indicated page (in this -example, the main page of the Google Search Engine). - -\section{more and Less} +\section{more and less} \large Marzio Lunghi \normalsize\\ + + Both commands show the content of one or more files and it’s possible to do a research with particular flags, but the “less” one allows us to go also backwards while reading the text of a file.\\ More is quite old, less is more recent and powerful.\\ -General syntax for both is:\\ +General syntax for both is: + \begin{verbatim} less \[flags\] path/name-file.* more \[flags\] path/name-file.* \end{verbatim} + + The command \texttt{less} provides some useful commands to navigate and modify the file content. -Commands does not include flags, which are included under Options.\\ +Commands does not include flags, which are included under \emph{Options}. + Commands + + Such commands must be used once the file has been displayed. They are not flags. For a single operation there can be multiple commands. + \begin{itemize} \item \texttt{ENTER RETURN e \^E j \^N CR }: Scroll forward N lines, 1 by default, if N is not specified. @@ -2990,13 +2964,15 @@ They are not flags. For a single operation there can be multiple commands. Jumping + + Such commands must be used once the file has been displayed. They are not. For a single operation there can be multiple commands. \begin{itemize} - \item \texttt{ g < ESC-\textless }: + \item \texttt{ g \textless ESC-\textless }: Go to line N, by default 1, if N is not specified. - \item \texttt{ G > ESC-\textgreater }: + \item \texttt{ G \textgreater ESC-\textgreater }: Go to line N, by default the last one , if N is not specified. \item \texttt{ t }: Go to the (N-th) next tag. @@ -3020,6 +2996,164 @@ character preceded by a "-", or a name preceded by "--" . Do not display tildes after end of file. \end{itemize} +\section{ls} + + +\large Alessandro Marinelli \normalsize\\ + + +The \texttt{ls} command is used to list a directory content or a file.\\ +The name stands for \emph{LiSt}. + +The default ls command syntax is: + +\begin{verbatim} +ls \[flags\] \[path\] +\end{verbatim} + +Where \[flags\] are the ls flags, read below for more info,and \[path\] is the +(optional) path (absolute or relative).If no path is provided the current +directory is listed.\\ + +Usage + +List the elements on the current working directory +Let's see how to show a list containing the elements included in the +current working directory + +\begin{verbatim} +ls + Other Multimedia my-cat.jpg + Photos Videos +\end{verbatim} + +As you can see, typing \texttt{ls} in the Unix Shell, will give as output +the list of elements contained in the current working directory.\\ +Elements listed can be files (look for exemple at the element\emph{my-cat.jpg}), +such as other directories (look for example at the folder \emph{Photos}).\\ + +List the elements contained in a directory +\begin{verbatim} +ls Photos + 01.jpg 02.jpg + 03.jpg 04.jpg +\end{verbatim} + +As you can see, now the Unix Shell is showing us the elements contained +in the folder \emph{Photos}.\\ + +Show hidden files +You can include hidden files (those which name starts with ".") in +the displayed list using the \texttt{-a} flag. + +\begin{verbatim} +ls -a Photos + . 01.png + .. 02.png + .DS\_Store 03.png + .secret.png 04.jpg +\end{verbatim} + +As you can see, now the shell shows more files for the same directory.\\ + +Show list in long format + +\begin{verbatim} +ls -l + total 10816 + -rw-r--r--@ 1 YourName YourGroup 3143706 4 Ott 13:28 01.png + -rw-r--r--@ 1 YourName YourGroup 2269193 28 Ott 18:58 02.png + -rw-r--r--@ 1 YourName YourGroup 37900 28 Ott 22:07 03.png + -rw-r--r--@ 1 YourName YourGroup 75924 20 Ott 16:01 04.jpg +\end{verbatim} + +If the \texttt{-l} flag is given, the following information will be displayed for +each file: file mode, number of links, owner name, group name, number of +bytes in the file, abbreviated month, day-of-month file was last modified, +hour file last modified, minute file last modified, and the path. + +In addition, for each directory whose contents are displayed, the +total number of 512-byte blocks used by the files in the directory is +displayed on a line by itself, immediately before the information for the +files in the directory. + +\section{whatis} + + +\large Marzio Lunghi \normalsize\\ + + + +The \texttt{whatis} command gives you a brief description of a command. + +\begin{verbatim} +whatis command +\end{verbatim} + +It's similar to \texttt{man -f command} + +\section{clear} + + +\large Marzio Lunghi \normalsize\\ + + +If you want to clear the shell screen up to the start you have to digit +the \texttt{clear} command: + +\begin{verbatim} +clear +\end{verbatim} + +This command corresponds to the \texttt{ ⌘ + K } key combination on Mac OS + +\section{info} + + +\large Gianmarco De Vita \normalsize\\ + + +An \emph{.info} file is an information document created by Texinfo.\\ +It stores documentation in a book format with chapters, sections, +and subsections and can contain up to four layers of depth.\\ +Info documents are used for storing software help manuals and technical books.\\ +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\] +\end{verbatim} + +Look up for a specific string + +Using the \texttt{--apropos} flag followed by a string, you obtain as +output a list of all the contents which correspond to the string you wrote. + +\begin{verbatim} +info --apropos string +\end{verbatim} + +If the string you inserted has nothing to do with the content of the info files, +you will get a error message. For example: + +\begin{verbatim} +info --apropos duck + info: No available info files have `duck' in their indices. +\end{verbatim} + +An help with this command +Using the \texttt{-h} flag (which stands for help), you obtain as +output a brief paragraph in which are explained the features of this command.\\ + +Visit a specific \emph{.info} file + +Using the \texttt{-f} flag followed by the path and a \emph{.info} file, you +as output obtain the content of that file. + +\begin{verbatim} +info -f path/filename.info +\end{verbatim} + \section{say} @@ -3461,20 +3595,27 @@ Here are some other examples of absolute paths: -The \texttt{cd} command is used to change the working directory\\ -The name stands for \emph{Change Directory}.\\ +The \texttt{cd} command is used to change the working directory
+The name stands for \emph{Change Directory}.
The default cd command syntax is: + \begin{verbatim} cd \[flags\] \[path\] \end{verbatim} + + Where \[flags\] are the cd flags, read below for more info,and \[path\] is the -path (absolute or relative), of the directory which we want to make as working directory.\\ +path (absolute or relative), of the directory which we want to make as working directory. + Change the working directory -Let's see how to use the command \texttt{cd} in order to change the working directory + + +Let's see how to use the command \texttt{cd} in order to change the working directory: + \begin{verbatim} pwd @@ -3484,11 +3625,15 @@ pwd ~/Desktop/multimedia \end{verbatim} + + As you can see, we changed the working directory from ~ (which stands for HOME), to "multimedia". Now our Shell will work on the directory "multimedia" -until a new \texttt{cd} will occour.\\ +until a new \texttt{cd} will occour. -\textbf{ Notice:} If you want to move to a directory which is not contained in the + + +\textbf{Notice:} If you want to move to a directory which is not contained in the current working directory, you \underline{MUST} use the absolute path. @@ -3568,189 +3713,6 @@ grep d \textless animals.txt \textgreater d\_animals.txt ... \end{verbatim} -\section{Parameter expansion} - - -\large Marco Tereh \normalsize\\ - - - -There are some special operations that can be performed on -\underline{\href{variables.html}{variables}} and strings called parameter expansions. -The general syntax for all parameter expansions is this one: - -\begin{verbatim} - \${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} -\end{verbatim} - -If the variable VARIABLE exists and has a value (i.e. it is not null), this is equal to -the value of VARIABLE. -Otherwise, it is equal to DEFAULT\_VALUE.\\ - -Example: \texttt{echo "First name: \${firstname:-John}";}\\ - -\begin{verbatim} - \${VARIABLE:=DEFAULT\_VALUE} -\end{verbatim} - -If the variable VARIABLE exists and has a value, this is equal to the value of VARIABLE. -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} -\end{verbatim} - -If the variable VARIABLE exists and has a value, this is equal to the value of VARIABLE. -Otherwise, it prints ERR\_VALUE to STDERR and exits (meaning nothing else will be executed -after this).\\ -Example: \texttt{currdate=\${date:?Operation failed: date unknown};}\\ - -\begin{verbatim} - \${VARIABLE:+VALUE} -\end{verbatim} - -If the variable VARIABLE exists and has a value, this is equal to VALUE. -Otherwise, this has no effect.\\ -Example: \texttt{echo -e "reading from address \$read.\${write:+\\nWARNING: read and write set -at the same time}";}\\ - -All of these can also be written without the colon, in which case their meaning changes to -"If the variable VARIABLE exists at all (even if it is null), this is ..."\\ - -\begin{verbatim} - \${VARIABLE: NUMBER} -\end{verbatim} - -This is equal to the substring of the value of VARIABLE, starting at the character with -(0-based) index NUMBER.\\ -If NUMBER is negative, the substring starts NUMBER characters before the end of the string.\\ -Example: \texttt{lastname=\${fullname:\$firstnamelength};}\\ - -\begin{verbatim} - \${VARIABLE: FROM:LENGTH} -\end{verbatim} - -This is equal to the substring of the value of VARIABLE, starting at the character with (0-based) -index FROM with length LENGTH\\ -If FROM is negative, the substring starts FROM characters before the end of the string.\\ -Example: \texttt{lastname=\${middlename:\$firstnamelength:\$middlenamelength};}\\ - -\begin{verbatim} - \${\#VARIABLE} -\end{verbatim} - -This is equal to the length of the value of VARIABLE\\ -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}} -\end{verbatim} - -Further reading:
-the bash reference manual - -\section{Script Variables} - - -\large Dario Rasic \normalsize\\ - - - -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.\\ - - -Naming a variable - - -To name a variable in Unix we have to use only 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 -\end{verbatim} - - -Defining a variable - -To define a certain variable, we could use the following basecase: - -\begin{verbatim} -variable\_name=variable\_value -\end{verbatim} - - -Let me show you a simple example: - -\begin{verbatim} -VAR\_1=Strawberry -\end{verbatim} - - -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 - Strawberry -\end{verbatim} - - -Deleting a variable - -Deleting a variable means that 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 -\end{verbatim} - -which in our case would be: - -\begin{verbatim} -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 -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. -\end{verbatim} - -If we try to delete the variable, shell will give us the following value: - -\begin{verbatim} -VAR\_1="Strawberry" -unset VAR\_1 - VAR\_1: This variable is read only. -\end{verbatim} - \section{Script Base Commands} @@ -3805,39 +3767,7 @@ grep "D" animals Dolphin \end{verbatim} -\section{Script Special Variables} - - -\large Dario Rasic \normalsize\\ - - - -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.\\ - -\$\$ -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.\\ - -\begin{verbatim} -echo \$\$ - 11480 -\end{verbatim} - -\$0 -This variable will simply give us the filename of the current script. - -\$n -This variable corresponds to the arguments with which a script was invoked. -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. - -\section{For Loop} +\section{While Loop} \large Matteo Omenetti \normalsize\\ @@ -3845,167 +3775,134 @@ This variable gives us the process number of the last background command. -The second type of loops are for loops. -They follow this syntax: -\begin{verbatim} - for \[variable\] in \[list\] do - \[code\] - done -\end{verbatim} +Loops are an important concept in programming and therefore also in scripting. +Thanks to loops you are able to repeat an instruction +automatically several times, until a certain condition turns false.\\ -Their purpose is to \emph{iterate} over a list. Also, while loops could do this, -you might argue... \\ -Of course, they could, but for loops are specifically meant to do this. Therefore, for instance, -you don't have to declare your counter variable outside the loop. Most importantly, -this variable can be accessed from inside the loop. \\ +Two are the main types of loops: while and for. They both generate a repeating +piece of code, but with some key differences +that make them suitable for different needs while programming.\\ -For loops take this form: +While loops take this form: \begin{verbatim} -for VARIABLE in 1 2 3 4 5 .. N +while \[condition\] do command1 command2 - commandN + command3 + ... done \end{verbatim} -Here is a simple example: +Here is a first simple example: \begin{verbatim} -for i in 1 2 3 4 5 +i=0; + +while \[\$i -lt 4\] do - echo "Welcome \$i times" + echo \$i + i=\$((i + 1)) done \end{verbatim} -This first example of code simply displays a welcome message 5 times. +In this first example, you simply create a variable called i and evaluate it to 0. +Then you access the while loop: the condition \texttt{ \[\$i -lt 4\]} means that this while +loop will run until the \texttt{ i} variable is less than 4. +Every cycle of this loop, you print out the value of variable i with \texttt{ echo \$i} +and finally, you increase its value by 1 with \texttt{ i=\$((i + 1))}. +Therefore in 4 cycles the value of i will be 4. This will make the condition of the while loop false. The output of this piece of code is: \begin{verbatim} - Welcome 1 times - Welcome 2 times - Welcome 3 times - Welcome 4 times - Welcome 5 times -\end{verbatim} + 0 + 1 + 2 + 3 + \end{verbatim} -There are also other ways to specify the \emph{ numerical range }. For instance, if -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, -0 2 4 6... 10. -\section{Arrays} - - -\large Marco Tereh \normalsize\\ - - - -There is a special kind of \underline{\href{variables.html}{variable}}, called an array.\\ - -While variables hold a single value, arrays hold many. They could be called a list of variables. -The simplest way to create an array is using this format: - +Sometimes it is required to declare infinite loops for various programming purposes. \\ +Here is an example: \begin{verbatim} - names=("Anna" "Bob" "Clarice" "Dee") +i=1; + +while : +do + printf "i=\$i\i: Hello World" + if \[ \$i == 3 \]; then + echo "I love DrRacket" + elif \[ \$i == 5\]; then + echo "I love Bash" + elif \[ \$i == 7 \]; then + echo "I love this website" + elif \[ \$i == 9 \]; then + exit 0 + i=\$((i + 1)) +done \end{verbatim} -This will create an array, called \texttt{names}, which holds 4 values. -The values in the array can be accessed using the syntax +No termination condition is set for this loop in this example. This type of loop +is called 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 +statement will evaluate to true and the loop will be terminated. \\ +The output of this piece of code is: \begin{verbatim} - \${names\[SELECTOR\]} + 1: Hello World + 2: Hello World + 3: Hello World + I love programming + 4: Hello World + 5: Hello World + I love Bash + 6: Hello World + 7: Hello World + I love this website + 8: Hello World + 9: Hello World \end{verbatim} -where SELECTOR is the selector associated to the desired element. There are two kinds of -arrays, depending on what kind of selector is used.\\ -\texttt{names} is an \emph{indexed} array, meaning the selector is a number. -Since we didn't specify any when we defined it, \texttt{names}' selectors start at -0 and count up from there.\\ -Thus we can access the string \texttt{"Anna"} using \texttt{names\[0\]}. -In the same way we use \texttt{names\[1\]} to access \texttt{"Bob"} and so on.\\ - -If we want to specify a particular index for our values when creating the array -we can do it like this: +If you want your shell to hang forever doing nothing you can write out the following infinite loop: \begin{verbatim} - names=(\[1\]="Anna" \[2\]="Bob" \[5\]="Ernie" \[12\]="Luigi") +while : +do + : +done \end{verbatim} -As you might have guessed, this will create an array with \texttt{"Anna"} at index 1, -\texttt{"Bob"} at index 2, \texttt{"Ernie"} at index 3 and so on.\\ -If our indices are all sequential and we just want to change the starting index, we can use +In scripting, while loops are often used to process files line by line. \\ +Here is an example: \begin{verbatim} - names=(\[12\]="Luigi" "Mario" "Nate") +while read -r first\_name last\_name phone; +do + printf '\%s\\n' "\$last\_name" +done \textless "\$file" \end{verbatim} -Which will create an array with \emph{"Luigi"} at index 12, -\emph{"Mario"} at index 13 and \emph{"Nate"} at index 14.\\ -An indexed array's selector can also be negative, which will start counting from the end, -so \emph{\${names\[-1\]}} means \emph{"Nate"}, \texttt{\${names\[-3\]}} is -\emph{"Luigi"} and so on.\\ +The \texttt{ read } command is used to read a file line by line. +The flag \texttt{ -r} is used to tell the +command read to interpret backslashes (/) literally, instead as escape characters. +This command, expect for some few +rare cases, should always be used with this flag. +In this example, \texttt{ \textless "\$file"} redirects the loop's input from a file +whose name is stored in a variable. +This file has 3 columns, \texttt{ first\_name last\_name phone }, separated by +blank space (or a tab). +This piece of code only prints out the second column. -The other kind of array is an \emph{associative} array. -In an associative array, the values are not mapped to a number but to some other string.\\ -Here's an example of an associative array: - -\begin{verbatim} - 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 -that "follows" white. To access its members, we use the same syntax but write a string -instead of a number as the selector.\\ -Arrays, both kinds, can also be modified after creation. We can use - -\begin{verbatim} - 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\] -\end{verbatim} - -to remove one.\\ - -The \texttt{@} and \texttt{*} selectors are special - they cannot be written to but -reading from them will return \textbf{all} the values in the array, separated by spaces. -Similarly, \texttt{\${!colors\[@\]}} is a list of -all the selectors (or indices) that were assigned a value.\\ - -\underline{\href{parameter\_expansion.html}{Parameter Expansion}} works on indexed arrays as well, -much like it works on strings, but it manipulates the members of the array instead of characters. -For example: - -\begin{verbatim} - \${names\[@\]: 13} -\end{verbatim} - -is equivalent to \texttt{"Mario" "Luigi"}, while - -\begin{verbatim} - \${\#names\[@\]} -\end{verbatim} - -counts the number of elements in the array, in this case 3.\\ - -Further reading: -the bash reference manual - -\section{If Statement} +\section{If statement} \large Matteo Omenetti \normalsize\\ @@ -4143,7 +4040,7 @@ Therefore, the output of this piece of code is: You chose 150. \end{verbatim} -\section{While Loop} +\section{For Loop} \large Matteo Omenetti \normalsize\\ @@ -4151,130 +4048,378 @@ Therefore, the output of this piece of code is: -Loops are an important concept in programming and therefore also in scripting. -Thanks to loops you are able to repeat an instruction -automatically several times, until a certain condition turns false.\\ - -Two are the main types of loops: while and for. They both generate a repeating -piece of code, but with some key differences -that make them suitable for different needs while programming.\\ - -While loops take this form: +The second type of loops are for loops. +They follow this syntax: \begin{verbatim} -while \[condition\] + for \[variable\] in \[list\] do + \[code\] + done +\end{verbatim} + +Their purpose is to \emph{iterate} over a list. Also, while loops could do this, +you might argue... \\ +Of course, they could, but for loops are specifically meant to do this. Therefore, for instance, +you don't have to declare your counter variable outside the loop. Most importantly, +this variable can be accessed from inside the loop. \\ + +For loops take this form: +\begin{verbatim} +for VARIABLE in 1 2 3 4 5 .. N do command1 command2 - command3 - ... + commandN done \end{verbatim} -Here is a first simple example: +Here is a simple example: \begin{verbatim} -i=0; - -while \[\$i -lt 4\] +for i in 1 2 3 4 5 do - echo \$i - i=\$((i + 1)) + echo "Welcome \$i times" done \end{verbatim} -In this first example, you simply create a variable called i and evaluate it to 0. -Then you access the while loop: the condition \texttt{ \[\$i -lt 4\]} means that this while -loop will run until the \texttt{ i} variable is less than 4. -Every cycle of this loop, you print out the value of variable i with \texttt{ echo \$i} -and finally, you increase its value by 1 with \texttt{ i=\$((i + 1))}. -Therefore in 4 cycles the value of i will be 4. This will make the condition of the while loop false. +This first example of code simply displays a welcome message 5 times. The output of this piece of code is: \begin{verbatim} - 0 - 1 - 2 - 3 - \end{verbatim} - - - - - -Sometimes it is required to declare infinite loops for various programming purposes. \\ -Here is an example: -\begin{verbatim} -i=1; - -while : -do - printf "i=\$i\i: Hello World" - if \[ \$i == 3 \]; then - echo "I love DrRacket" - elif \[ \$i == 5\]; then - echo "I love Bash" - elif \[ \$i == 7 \]; then - echo "I love this website" - elif \[ \$i == 9 \]; then - exit 0 - 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.\\ -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 -statement will evaluate to true and the loop will be terminated. \\ - -The output of this piece of code is: -\begin{verbatim} - 1: Hello World - 2: Hello World - 3: Hello World - I love programming - 4: Hello World - 5: Hello World - I love Bash - 6: Hello World - 7: Hello World - I love this website - 8: Hello World - 9: Hello World + Welcome 1 times + Welcome 2 times + Welcome 3 times + Welcome 4 times + Welcome 5 times \end{verbatim} +There are also other ways to specify the \emph{ numerical range }. For instance, if +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, +0 2 4 6... 10. + + +\section{Script Variables} + + +\large Dario Rasic \normalsize\\ + + + +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.\\ + + +Naming a variable + + +To name a variable in Unix we have to use only 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: -If you want your shell to hang forever doing nothing you can write out the following infinite loop: \begin{verbatim} -while : -do - : -done +VAR\_1 +VAR\_2 +NAME\_3 +name\_4 \end{verbatim} +Defining a variable + +To define a certain variable, we could use the following basecase: -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; -do - printf '\%s\\n' "\$last\_name" -done \textless "\$file" +variable\_name=variable\_value \end{verbatim} -The \texttt{ read } command is used to read a file line by line. -The flag \texttt{ -r} is used to tell the -command read to interpret backslashes (/) literally, instead as escape characters. -This command, expect for some few -rare cases, should always be used with this flag. -In this example, \texttt{ \textless "\$file"} redirects the loop's input from a file -whose name is stored in a variable. -This file has 3 columns, \texttt{ first\_name last\_name phone }, separated by -blank space (or a tab). -This piece of code only prints out the second column. +Let me show you a simple example: + +\begin{verbatim} +VAR\_1=Strawberry +\end{verbatim} + + +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 + Strawberry +\end{verbatim} + + +Deleting a variable + +Deleting a variable means that 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 +\end{verbatim} + +which in our case would be: + +\begin{verbatim} +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 +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. +\end{verbatim} + +If we try to delete the variable, shell will give us the following value: + +\begin{verbatim} +VAR\_1="Strawberry" +unset VAR\_1 + VAR\_1: This variable is read only. +\end{verbatim} + +\section{Parameter expansion} + + +\large Marco Tereh \normalsize\\ + + + +There are some special operations that can be performed on +\underline{\href{variables.html}{variables}} and strings called parameter expansions. +The general syntax for all parameter expansions is this one: + +\begin{verbatim} + \${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} +\end{verbatim} + +If the variable VARIABLE exists and has a value (i.e. it is not null), this is equal to +the value of VARIABLE. +Otherwise, it is equal to DEFAULT\_VALUE.\\ + +Example: \texttt{echo "First name: \${firstname:-John}";}\\ + +\begin{verbatim} + \${VARIABLE:=DEFAULT\_VALUE} +\end{verbatim} + +If the variable VARIABLE exists and has a value, this is equal to the value of VARIABLE. +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} +\end{verbatim} + +If the variable VARIABLE exists and has a value, this is equal to the value of VARIABLE. +Otherwise, it prints ERR\_VALUE to STDERR and exits (meaning nothing else will be executed +after this).\\ +Example: \texttt{currdate=\${date:?Operation failed: date unknown};}\\ + +\begin{verbatim} + \${VARIABLE:+VALUE} +\end{verbatim} + +If the variable VARIABLE exists and has a value, this is equal to VALUE. +Otherwise, this has no effect.\\ +Example: \texttt{echo -e "reading from address \$read.\${write:+\\nWARNING: read and write set +at the same time}";}\\ + +All of these can also be written without the colon, in which case their meaning changes to +"If the variable VARIABLE exists at all (even if it is null), this is ..."\\ + +\begin{verbatim} + \${VARIABLE: NUMBER} +\end{verbatim} + +This is equal to the substring of the value of VARIABLE, starting at the character with +(0-based) index NUMBER.\\ +If NUMBER is negative, the substring starts NUMBER characters before the end of the string.\\ +Example: \texttt{lastname=\${fullname:\$firstnamelength};}\\ + +\begin{verbatim} + \${VARIABLE: FROM:LENGTH} +\end{verbatim} + +This is equal to the substring of the value of VARIABLE, starting at the character with (0-based) +index FROM with length LENGTH\\ +If FROM is negative, the substring starts FROM characters before the end of the string.\\ +Example: \texttt{lastname=\${middlename:\$firstnamelength:\$middlenamelength};}\\ + +\begin{verbatim} + \${\#VARIABLE} +\end{verbatim} + +This is equal to the length of the value of VARIABLE\\ +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}} +\end{verbatim} + +Further reading: +the bash reference manual + +\section{Script Special Variables} + + +\large Dario Rasic \normalsize\\ + + + +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.\\ + +\$\$ +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.\\ + +\begin{verbatim} +echo \$\$ + 11480 +\end{verbatim} + +\$0 +This variable will simply give us the filename of the current script. + +\$n +This variable corresponds to the arguments with which a script was invoked. +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. + +\section{Arrays} + + +\large Marco Tereh \normalsize\\ + + + +There is a special kind of \underline{\href{variables.html}{variable}}, called an array.\\ + +While variables hold a single value, arrays hold many. They could be called a list of variables. +The simplest way to create an array is using this format: + +\begin{verbatim} + names=("Anna" "Bob" "Clarice" "Dee") +\end{verbatim} + +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\]} +\end{verbatim} + +where SELECTOR is the selector associated to the desired element. There are two kinds of +arrays, depending on what kind of selector is used.\\ + +\texttt{names} is an \emph{indexed} array, meaning the selector is a number. +Since we didn't specify any when we defined it, \texttt{names}' selectors start at +0 and count up from there.\\ + +Thus we can access the string \texttt{"Anna"} using \texttt{names\[0\]}. +In the same way we use \texttt{names\[1\]} to access \texttt{"Bob"} and so on.\\ + +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") +\end{verbatim} + +As you might have guessed, this will create an array with \texttt{"Anna"} at index 1, +\texttt{"Bob"} at index 2, \texttt{"Ernie"} at index 3 and so on.\\ + +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") +\end{verbatim} + +Which will create an array with \emph{"Luigi"} at index 12, +\emph{"Mario"} at index 13 and \emph{"Nate"} at index 14.\\ +An indexed array's selector can also be negative, which will start counting from the end, +so \emph{\${names\[-1\]}} means \emph{"Nate"}, \texttt{\${names\[-3\]}} is +\emph{"Luigi"} and so on.\\ + +The other kind of array is an \emph{associative} array. +In an associative array, the values are not mapped to a number but to some other string.\\ + +Here's an example of an associative array: + +\begin{verbatim} + 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 +that "follows" white. To access its members, we use the same syntax but write a string +instead of a number as the selector.\\ +Arrays, both kinds, can also be modified after creation. We can use + +\begin{verbatim} + 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\] +\end{verbatim} + +to remove one.\\ + +The \texttt{@} and \texttt{*} selectors are special - they cannot be written to but +reading from them will return \textbf{all} the values in the array, separated by spaces. +Similarly, \texttt{\${!colors\[@\]}} is a list of +all the selectors (or indices) that were assigned a value.\\ + +\underline{\href{parameter\_expansion.html}{Parameter Expansion}} works on indexed arrays as well, +much like it works on strings, but it manipulates the members of the array instead of characters. +For example: + +\begin{verbatim} + \${names\[@\]: 13} +\end{verbatim} + +is equivalent to \texttt{"Mario" "Luigi"}, while + +\begin{verbatim} + \${\#names\[@\]} +\end{verbatim} + +counts the number of elements in the array, in this case 3.\\ + +Further reading: +the bash reference manual \end{document} diff --git a/site/pages/cmd/interm/ping.html b/site/pages/cmd/interm/ping.html index b797208..a17aade 100644 --- a/site/pages/cmd/interm/ping.html +++ b/site/pages/cmd/interm/ping.html @@ -9,6 +9,8 @@ previous-page: pages/cmd/interm/passwd.html next-page: pages/cmd/interm/ps.html --- + + The ping command, is used to test connection between a local server/computer to a remote UNIX server.
The ping command sends ICMP Echo Request packets to the remote server for accessing it.