{"id":42,"date":"2022-03-04T15:11:17","date_gmt":"2022-03-04T20:11:17","guid":{"rendered":"https:\/\/pressbooks.library.ryerson.ca\/opsyshiraki\/chapter\/quick-reference-guide\/"},"modified":"2022-10-07T16:50:57","modified_gmt":"2022-10-07T20:50:57","slug":"quick-reference-guide","status":"publish","type":"chapter","link":"https:\/\/pressbooks.library.torontomu.ca\/opsyshiraki\/chapter\/quick-reference-guide\/","title":{"raw":"Quick Reference Guide","rendered":"Quick Reference Guide"},"content":{"raw":"<h1>Common Notations<\/h1>\r\nHere are some commonly used but easy-to-forget notations and syntax.\r\n<table class=\"grid\" style=\"border-collapse: collapse;width: 100%\" border=\"0\">\r\n<thead>\r\n<tr>\r\n<th style=\"width: 33.3333%;font-size: 1.2em\" scope=\"col\">Notation<\/th>\r\n<th style=\"width: 33.3333%;font-size: 1.2em\" scope=\"col\">Typical usage with mini-example<\/th>\r\n<th style=\"width: 33.3333%;font-size: 1.2em\" scope=\"col\">Where to get more info<\/th>\r\n<\/tr>\r\n<\/thead>\r\n<tbody>\r\n<tr>\r\n<td style=\"width: 33.3333%\">single quotes (')<\/td>\r\n<td style=\"width: 33.3333%\">Creates literal string protecting special characters.\r\n<pre>grep 'Al Shaji' namelist<\/pre>\r\n<\/td>\r\n<td style=\"width: 33.3333%\"><a href=\"https:\/\/pressbooks.library.ryerson.ca\/opsyshiraki\/chapter\/shellvariables\/\">Shell Variables<\/a><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 33.3333%\">double quotes (\")<\/td>\r\n<td style=\"width: 33.3333%\">Like single quotes but interprets $, \\ for variables.\r\n<pre>echo \"Price: $value\"<\/pre>\r\n<\/td>\r\n<td style=\"width: 33.3333%\"><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 33.3333%\">$(cmd)<\/td>\r\n<td style=\"width: 33.3333%\">Command substitution.\u00a0 Runs cmd and substitutes output of cmd at position of call.\r\n<pre>today=$(date)<\/pre>\r\n<\/td>\r\n<td style=\"width: 33.3333%\">man bash\r\n\r\n&nbsp;<\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 33.3333%\">set braces { }<\/td>\r\n<td style=\"width: 33.3333%\">Formal variable specification; substrings.\r\n<pre>echo ${alpha:3:5}<\/pre>\r\n3 is offset (zero-based) and 5 is length<\/td>\r\n<td style=\"width: 33.3333%\"><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 33.3333%\">double parentheses (( ))<\/td>\r\n<td style=\"width: 33.3333%\">Arithmetic expression.\r\n<pre>a=$(( $a + 1 ))<\/pre>\r\n<\/td>\r\n<td style=\"width: 33.3333%\">man bash<\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 33.3333%\">left square bracket [<\/td>\r\n<td style=\"width: 33.3333%\">Synonym for test command.\r\n<pre>if [ $op = MR ]<\/pre>\r\nClosing right bracket is needed.<\/td>\r\n<td style=\"width: 33.3333%\">man test<\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 33.3333%\">[[ string =~ regex ]]<\/td>\r\n<td style=\"width: 33.3333%\">Checks to see if regular expression (regex) is contained in string\r\n\r\nExample\r\n\r\n[[ importing =~ port ]] will return TRUE\r\n\r\nCan be used with variables, too.\r\n\r\nExample\r\n\r\n[[ $title =~ $word ]] returns TRUE if $word is contained within $title<\/td>\r\n<td style=\"width: 33.3333%\">man bash<\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 33.3333%\">Character classes in regular expressions\r\n\r\n[abc]<\/td>\r\n<td style=\"width: 33.3333%\">Square brackets represent a single character pattern.\u00a0 Thus,\r\n\r\nr[aou]n matches ran, ron, or run.\r\n\r\n[Pp]olish matches Polish or polish<\/td>\r\n<td style=\"width: 33.3333%\">man regex.7\r\n\r\n&nbsp;<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<h1>FAQs<\/h1>\r\nQ1a: How do make my script executable?\r\n\r\nQ1b: I'm getting an error message, \"-bash: .\/myscript: Permission denied\"\r\n\r\nA1: You need to issue the chmod command, either:\r\n<ul>\r\n \t<li>\r\n<pre>chmod 700 myscript<\/pre>\r\n<\/li>\r\n \t<li>\r\n<pre>chmod u+x myscript<\/pre>\r\n<\/li>\r\n<\/ul>\r\n&nbsp;","rendered":"<h1>Common Notations<\/h1>\n<p>Here are some commonly used but easy-to-forget notations and syntax.<\/p>\n<table class=\"grid\" style=\"border-collapse: collapse;width: 100%\">\n<thead>\n<tr>\n<th style=\"width: 33.3333%;font-size: 1.2em\" scope=\"col\">Notation<\/th>\n<th style=\"width: 33.3333%;font-size: 1.2em\" scope=\"col\">Typical usage with mini-example<\/th>\n<th style=\"width: 33.3333%;font-size: 1.2em\" scope=\"col\">Where to get more info<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"width: 33.3333%\">single quotes (&#8216;)<\/td>\n<td style=\"width: 33.3333%\">Creates literal string protecting special characters.<\/p>\n<pre>grep 'Al Shaji' namelist<\/pre>\n<\/td>\n<td style=\"width: 33.3333%\"><a href=\"https:\/\/pressbooks.library.ryerson.ca\/opsyshiraki\/chapter\/shellvariables\/\">Shell Variables<\/a><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 33.3333%\">double quotes (&#8220;)<\/td>\n<td style=\"width: 33.3333%\">Like single quotes but interprets $, \\ for variables.<\/p>\n<pre>echo \"Price: $value\"<\/pre>\n<\/td>\n<td style=\"width: 33.3333%\"><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 33.3333%\">$(cmd)<\/td>\n<td style=\"width: 33.3333%\">Command substitution.\u00a0 Runs cmd and substitutes output of cmd at position of call.<\/p>\n<pre>today=$(date)<\/pre>\n<\/td>\n<td style=\"width: 33.3333%\">man bash<\/p>\n<p>&nbsp;<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 33.3333%\">set braces { }<\/td>\n<td style=\"width: 33.3333%\">Formal variable specification; substrings.<\/p>\n<pre>echo ${alpha:3:5}<\/pre>\n<p>3 is offset (zero-based) and 5 is length<\/td>\n<td style=\"width: 33.3333%\"><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 33.3333%\">double parentheses (( ))<\/td>\n<td style=\"width: 33.3333%\">Arithmetic expression.<\/p>\n<pre>a=$(( $a + 1 ))<\/pre>\n<\/td>\n<td style=\"width: 33.3333%\">man bash<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 33.3333%\">left square bracket [<\/td>\n<td style=\"width: 33.3333%\">Synonym for test command.<\/p>\n<pre>if [ $op = MR ]<\/pre>\n<p>Closing right bracket is needed.<\/td>\n<td style=\"width: 33.3333%\">man test<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 33.3333%\">[[ string =~ regex ]]<\/td>\n<td style=\"width: 33.3333%\">Checks to see if regular expression (regex) is contained in string<\/p>\n<p>Example<\/p>\n<p>[[ importing =~ port ]] will return TRUE<\/p>\n<p>Can be used with variables, too.<\/p>\n<p>Example<\/p>\n<p>[[ $title =~ $word ]] returns TRUE if $word is contained within $title<\/td>\n<td style=\"width: 33.3333%\">man bash<\/td>\n<\/tr>\n<tr>\n<td style=\"width: 33.3333%\">Character classes in regular expressions<\/p>\n<p>[abc]<\/td>\n<td style=\"width: 33.3333%\">Square brackets represent a single character pattern.\u00a0 Thus,<\/p>\n<p>r[aou]n matches ran, ron, or run.<\/p>\n<p>[Pp]olish matches Polish or polish<\/td>\n<td style=\"width: 33.3333%\">man regex.7<\/p>\n<p>&nbsp;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h1>FAQs<\/h1>\n<p>Q1a: How do make my script executable?<\/p>\n<p>Q1b: I&#8217;m getting an error message, &#8220;-bash: .\/myscript: Permission denied&#8221;<\/p>\n<p>A1: You need to issue the chmod command, either:<\/p>\n<ul>\n<li>\n<pre>chmod 700 myscript<\/pre>\n<\/li>\n<li>\n<pre>chmod u+x myscript<\/pre>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n","protected":false},"author":2,"menu_order":7,"template":"","meta":{"pb_show_title":"on","pb_short_title":"","pb_subtitle":"","pb_authors":[],"pb_section_license":""},"chapter-type":[],"contributor":[],"license":[],"class_list":["post-42","chapter","type-chapter","status-publish","hentry"],"part":23,"_links":{"self":[{"href":"https:\/\/pressbooks.library.torontomu.ca\/opsyshiraki\/wp-json\/pressbooks\/v2\/chapters\/42","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pressbooks.library.torontomu.ca\/opsyshiraki\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/pressbooks.library.torontomu.ca\/opsyshiraki\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/pressbooks.library.torontomu.ca\/opsyshiraki\/wp-json\/wp\/v2\/users\/2"}],"version-history":[{"count":8,"href":"https:\/\/pressbooks.library.torontomu.ca\/opsyshiraki\/wp-json\/pressbooks\/v2\/chapters\/42\/revisions"}],"predecessor-version":[{"id":75,"href":"https:\/\/pressbooks.library.torontomu.ca\/opsyshiraki\/wp-json\/pressbooks\/v2\/chapters\/42\/revisions\/75"}],"part":[{"href":"https:\/\/pressbooks.library.torontomu.ca\/opsyshiraki\/wp-json\/pressbooks\/v2\/parts\/23"}],"metadata":[{"href":"https:\/\/pressbooks.library.torontomu.ca\/opsyshiraki\/wp-json\/pressbooks\/v2\/chapters\/42\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/pressbooks.library.torontomu.ca\/opsyshiraki\/wp-json\/wp\/v2\/media?parent=42"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/pressbooks.library.torontomu.ca\/opsyshiraki\/wp-json\/pressbooks\/v2\/chapter-type?post=42"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/pressbooks.library.torontomu.ca\/opsyshiraki\/wp-json\/wp\/v2\/contributor?post=42"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/pressbooks.library.torontomu.ca\/opsyshiraki\/wp-json\/wp\/v2\/license?post=42"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}