{"id":35,"date":"2022-03-04T15:11:16","date_gmt":"2022-03-04T20:11:16","guid":{"rendered":"https:\/\/pressbooks.library.ryerson.ca\/opsyshiraki\/chapter\/shellvariables\/"},"modified":"2023-09-01T13:25:15","modified_gmt":"2023-09-01T17:25:15","slug":"shellvariables","status":"publish","type":"chapter","link":"https:\/\/pressbooks.library.torontomu.ca\/opsyshiraki\/chapter\/shellvariables\/","title":{"raw":"Shell Variables, Quotes, Command Substitution","rendered":"Shell Variables, Quotes, Command Substitution"},"content":{"raw":"<h1>Shell Variables<\/h1>\r\n<p class=\"c4\"><span class=\"c0\">Unix is an operating system but also the name given to its scripting (programming) language. In order to be useful, a computer language needs to be able to store data. Unix supports this capability with shell variables. <\/span><\/p>\r\n<p class=\"c4\"><span class=\"c0\">There are three kinds of shell variables:<\/span><\/p>\r\n\r\n<ol class=\"c2 lst-kix_ckfao24sw02h-0 start\" start=\"1\">\r\n \t<li class=\"c4 c12 c9 li-bullet-0\"><span class=\"c0\">special<\/span><\/li>\r\n \t<li class=\"c4 c12 c9 li-bullet-0\"><span class=\"c0\">environment<\/span><\/li>\r\n \t<li class=\"c4 c12 c9 li-bullet-0\"><span class=\"c0\">program<\/span><\/li>\r\n<\/ol>\r\n<h2 id=\"h.g9x11nt2qx8t\" class=\"c13 c6\"><span class=\"c10\">Special variables<\/span><\/h2>\r\n<p class=\"c4\"><span class=\"c0\">Special variables are unlike what you may have seen in other programming languages. Rather special variables are created and set by the operating system automatically. Consider the following examples:<\/span><\/p>\r\n<p class=\"c3\"><span class=\"c0\">\u00a0<\/span><\/p>\r\n\r\n<h3 class=\"c5\" id=\"h.3gv6p8mlyjaa\"><span class=\"c8\">Positional parameters ($1, $2, \u2026)<\/span><\/h3>\r\n<p class=\"c4\"><span class=\"c0\">Recall that the cat program allows the user to specify inputs as command-line arguments:\u00a0 (In the following examples, the leading dollar sign represents the command prompt; do not type the leading dollar sign.)<\/span><\/p>\r\n\r\n<pre class=\"c4\"><span class=\"c0\">$ <strong>cat ch1 ch2 ch3<\/strong><\/span><\/pre>\r\n<p class=\"c4\"><span class=\"c0\">Imagine that you would like to write your own script allowing the user to specify inputs as command-line arguments as in. <\/span><\/p>\r\n&nbsp;\r\n<pre class=\"c4\"><span class=\"c0\">$ <strong>myscript apple cherry<\/strong><\/span><\/pre>\r\n<div class=\"textbox textbox--examples\"><header class=\"textbox__header\">\r\n<p class=\"textbox__title\">Example<\/p>\r\n\r\n<\/header>\r\n<div class=\"textbox__content\">\r\n<pre class=\"c4\"><span class=\"c1\">$ <strong>cat arg_demo<\/strong><\/span>\r\n<span class=\"c1\">#!\/bin\/bash<\/span>\r\n<span class=\"c1\">echo The 1st argument is $1<\/span>\r\n<span class=\"c1\">echo The 2nd argument is $2<\/span>\r\n$\r\n<span class=\"c1\">$ <strong>.\/arg_demo apple cherry<\/strong><\/span>\r\n<span class=\"c1\">The 1st argument is apple<\/span>\r\n<span class=\"c1\">The 2nd argument is cherry<\/span>\r\n\r\n<\/pre>\r\n<\/div>\r\n<\/div>\r\n<h3 class=\"c5\" id=\"h.xrhmgnq10kfz\"><span class=\"c8\">number of command line arguments ($#)<\/span><\/h3>\r\n<p class=\"c4\"><span class=\"c0\">The special variable $# holds the number of command-line arguments specified when your script was run.<\/span><\/p>\r\n\r\n<div class=\"textbox textbox--examples\"><header class=\"textbox__header\">\r\n<p class=\"textbox__title\">Examples<\/p>\r\n\r\n<\/header>\r\n<div class=\"textbox__content\">\r\n<pre>$ <strong>cat numeg<\/strong>\r\n<span class=\"c1\">#!\/bin\/bash\r\n<\/span><span class=\"c1\">echo The number of command line arguments is $#\r\n$\r\n$ <strong>.\/numeg apple<\/strong><\/span><strong><span class=\"c1\"> cherry\r\n<\/span><\/strong><span class=\"c1\">The number of command line arguments is 2\r\n<\/span>$<\/pre>\r\n<\/div>\r\n<\/div>\r\n&nbsp;\r\n<h3 class=\"c5\" id=\"h.aq4mywhc5f8f\"><span class=\"c8\">return code of previous command ($?)<\/span><\/h3>\r\n<p class=\"c4\"><span class=\"c0\">Every Unix command generates a return code typically indicating success or failure. The value of this return code is stored in the special variable $?. Thus each time a Unix command is run the $? variable is updated automatically to hold the return code of the most recently executed Unix command. \u00a0The use of the return code is important and will become apparent in the chapter on control structures. <\/span><\/p>\r\n\r\n<h2 class=\"c13 c6\"><span class=\"c10\">Environment <\/span><span class=\"c10\">variables<\/span><\/h2>\r\n<p class=\"c4\"><span class=\"c0\">Environment variables hold information about the users's current settings and configuration. By convention, they are typically all UPPERCASE. To display them, type \u2018env\u2019<\/span><\/p>\r\n\r\n<div class=\"textbox textbox--examples\"><header class=\"textbox__header\">\r\n<p class=\"textbox__title\">Example<\/p>\r\n\r\n<\/header>\r\n<div class=\"textbox__content\">\r\n<pre class=\"c3\"><span class=\"c0\">lhiraki@metis:~$ <strong>env<\/strong>\r\nSHELL=\/bin\/bash\r\nPATH=\/usr\/local\/bin:\/usr\/bin:\/bin:\/usr\/local\/games:\/usr\/games:\/snap\/bin:\/usr\/courses\/bin\/x86_64\r\nJAVA_HOME=\/usr\/lib\/jvm\/java-8-openjdk-amd64\r\nEDITOR=vi\r\nLANGUAGE=en_CA:en\r\nLPDEST=eng206c\r\nlhiraki@metis:~$\r\n<\/span><\/pre>\r\nHere is an abridged list of environment variables.\u00a0 Some of the typical environment variables include SHELL (current shell), PATH (list of directories the operating system will search in order to find a command), EDITOR (preferred editor), LANGUAGE (preferred display language), LPDEST (preferred printer destination).\r\n\r\n<\/div>\r\n<\/div>\r\n&nbsp;\r\n<h2 class=\"c5\"><span class=\"c8\">Program <\/span><span class=\"c10\">variables<\/span><\/h2>\r\n<p class=\"c4\"><span class=\"c0\">Program variables are the type of variable that typically come to mind when one thinks of variables in a computer programming language. Program variables are variables which you as the programmer create and set. As Unix is a prototyping language, it is common to dispense with many of the formalities required for variable declarations, etc. <\/span><\/p>\r\n<p class=\"c3\"><span class=\"c0\">\u00a0<\/span><\/p>\r\n<p class=\"c4\"><span class=\"c0\">Program variables hold a string, i.e. text, and can be used anywhere text could appear in a program such as a filename, part of the file name, or even a Unix command itself. \u00a0A variable can hold only one value at a time. <\/span><\/p>\r\n<p class=\"c3\"><span class=\"c0\">\u00a0<\/span><\/p>\r\n<p class=\"c4\"><span class=\"c0\">The naming convention for program variables is to use lowercase. Specifically uppercase program variable names should be avoided so as to prevent confusion with environment variables and accidentally overwriting an environment variable.<\/span><\/p>\r\n<p class=\"c3\"><span class=\"c0\">\u00a0<\/span><\/p>\r\n<p class=\"c3\"><span class=\"c0\">\u00a0<\/span><\/p>\r\n<p class=\"c3\"><span class=\"c0\">\u00a0<\/span><\/p>\r\n\r\n<div class=\"textbox textbox--examples\"><header class=\"textbox__header\">\r\n<p class=\"textbox__title\"><span class=\"c0\">Eg. 1 \u00a0An easy way to create and set a program variable is using an assignment statement.<\/span><\/p>\r\n\r\n<\/header>\r\n<div class=\"textbox__content\">\r\n<pre id=\"h.7cl5azn9o175\" class=\"c4 c6\"><span class=\"c1\">temp_name=\/usr\/temp<\/span>\r\n<span class=\"c1\">cp myfile $temp_name<\/span><\/pre>\r\n<\/div>\r\n<\/div>\r\n<p class=\"c3\"><span class=\"c0\">\u00a0<\/span><\/p>\r\n<p class=\"c4\"><span class=\"c0\">Assignment statements copy the value to the right of the equal sign to the variable on the left. \u00a0Important: \u00a0Assignment statements must not contain spaces, especially around the equal sign.<\/span><\/p>\r\n<p class=\"c3\"><span class=\"c0\">\u00a0<\/span><\/p>\r\n\r\n<div class=\"textbox textbox--examples\"><header class=\"textbox__header\">\r\n<p class=\"textbox__title\">Eg. 2<\/p>\r\n\r\n<\/header>\r\n<div class=\"textbox__content\">\r\n<pre id=\"h.swweyesv5zvn\" class=\"c4 c6\"><span class=\"c1\">month=september <\/span>\r\n<span class=\"c1\">echo the current month is $month<\/span><\/pre>\r\n<\/div>\r\n<\/div>\r\n<h3 class=\"c5\" id=\"h.hzz5ibquuoql\"><span class=\"c8\">When to use $ with variables<\/span><\/h3>\r\n<p class=\"c4\"><span class=\"c0\">When writing to a variable, i.e. setting or changing its contents, do not use the dollar sign. When reading a variable, i.e. accessing its contents, you must use the dollar sign.<\/span><\/p>\r\n<p class=\"c3\"><span class=\"c0\">\u00a0<\/span><\/p>\r\n\r\n<div class=\"textbox textbox--key-takeaways\"><header class=\"textbox__header\">\r\n<p class=\"textbox__title\">Key Takeaway - <span class=\"c0\">When to use $ with variables:<\/span><\/p>\r\n\r\n<\/header>\r\n<div class=\"textbox__content\">\r\n<p class=\"c4\"><span class=\"c0\"><strong>Writing<\/strong> to a variable: <strong>no<\/strong> dollar sign<\/span><\/p>\r\n<p class=\"c4\"><span class=\"c0\"><strong>Reading<\/strong> from a variable: <strong>use<\/strong> dollar sign<\/span><\/p>\r\n\r\n<\/div>\r\n<\/div>\r\n<div class=\"textbox shaded\">\r\n<p class=\"c3\">Editorial Remark:<\/p>\r\nOne of the key factors affected software maintenance costs is code readability.\u00a0 Most of the time (cost) of maintaining software is spent in having designers read and understand existing code.\u00a0 One way to control and reduce costs (business competitiveness) is to ease readability.\u00a0 By choosing variables which reflect their contents, it makes it easier to understand the code.\r\n<p class=\"c4\"><strong><span class=\"c0\">Choose self-describing variable names:<\/span><\/strong><\/p>\r\n\r\n<table class=\"grid\" style=\"border-collapse: collapse;width: 100%;height: 30px\" border=\"0\">\r\n<thead>\r\n<tr style=\"height: 15px\">\r\n<th style=\"width: 50%;height: 15px\" scope=\"col\"><span style=\"font-size: 16px\">Good variable names:<\/span><\/th>\r\n<th style=\"width: 50%;height: 15px\" scope=\"col\"><span class=\"c0\">Bad variable names:<\/span><\/th>\r\n<\/tr>\r\n<\/thead>\r\n<tbody>\r\n<tr style=\"height: 15px\">\r\n<td style=\"width: 50%;height: 15px\">\r\n<ul class=\"c2 lst-kix_furawtezqk8i-0 start\">\r\n \t<li class=\"c4 c12 c9 li-bullet-0\"><span class=\"c0\">sum <\/span><\/li>\r\n \t<li class=\"c4 c12 c9 li-bullet-0\"><span class=\"c0\">total<\/span><\/li>\r\n \t<li class=\"c4 c12 c9 li-bullet-0\"><span class=\"c0\">x_value<\/span><\/li>\r\n \t<li class=\"c4 c12 c9 li-bullet-0\"><span class=\"c0\">length <\/span><\/li>\r\n \t<li class=\"c4 c12 c9 li-bullet-0\"><span class=\"c0\">count<\/span><\/li>\r\n<\/ul>\r\n<\/td>\r\n<td style=\"width: 50%;height: 15px\">\r\n<ul class=\"c2 lst-kix_14tmntyk4v1-0 start\">\r\n \t<li class=\"c4 c12 c9 li-bullet-0\"><span class=\"c0\">a,b,c\u2026.<\/span><\/li>\r\n \t<li class=\"c4 c12 c9 li-bullet-0\"><span class=\"c0\">var1, var2, var3\u2026.<\/span><\/li>\r\n<\/ul>\r\n<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<span style=\"text-align: initial;font-size: 1em\">\u00a0<\/span>\r\n\r\n<\/div>\r\n<h1 id=\"h.1bkln71pd17i\" class=\"c13 c6\"><span class=\"c10\">read<\/span><\/h1>\r\n<p class=\"c4\"><span class=\"c0\">The read command collects characters from standard input (STDIN) and stores them in a variable. \u00a0The read command is typically used in an interactive script to collect user input after an appropriate prompt message. \u00a0As the read command draws from standard input, and standard input can be redirected from a file, it is possible to prepare inputs (answers) in a file and run the script in a non-interactive fashion.<\/span><\/p>\r\n<p class=\"c3\"><span class=\"c0\">\u00a0<\/span><\/p>\r\n\r\n<div class=\"textbox textbox--examples\"><header class=\"textbox__header\">\r\n<p class=\"textbox__title\">Example using read command<\/p>\r\n\r\n<\/header>\r\n<div class=\"textbox__content\">\r\n<pre id=\"h.3pe0qxhk8bnw\" class=\"c4 c6\"><span class=\"c1\">$ <strong>cat readeg<\/strong><\/span>\r\n<span class=\"c1\">echo -n 'What is your name? '<\/span>\r\n<span class=\"c1\">read name<\/span>\r\n<span class=\"c1\">echo Hello $name, pleased to meet you!<\/span>\r\n<span class=\"c1\">$<\/span>\r\n<span class=\"c1\">$ <strong>.\/readeg<\/strong><\/span>\r\n<span class=\"c1\">What is your name? <strong>Mohammed<\/strong><\/span>\r\n<span class=\"c1\">Hello Mohammed, pleased to meet you!<\/span>\r\n<span class=\"c1\">$<\/span><\/pre>\r\n<\/div>\r\n<\/div>\r\n<div class=\"textbox shaded\">\r\n\r\nWhat does the option \"-n\" do in the echo command above?\r\n\r\nHint: type \"man echo\".\u00a0 To exit the manual, press \"q\".\r\n\r\n<\/div>\r\n<div><\/div>\r\n<div class=\"textbox textbox--key-takeaways\"><header class=\"textbox__header\">\r\n<p class=\"textbox__title\">Key Takeaways<\/p>\r\n\r\n<\/header>\r\n<div class=\"textbox__content\">\r\n<p class=\"c4\"><span class=\"c0\">read vs. command line arguments<\/span><\/p>\r\n\r\n<ul>\r\n \t<li class=\"c4\"><span class=\"c0\">Both are ways the user can supply input to a program.\u00a0 Command line arguments are placed on the command line before pressing &lt;ENTER&gt; to run the program.\u00a0 The values are accessed within one's program using $1, $2, etc.<\/span><\/li>\r\n \t<li class=\"c4\"><span class=\"c0\">The \"read\" command causes the program to wait for keyboard input (if STDIN has not been redirected from a file).\u00a0 The input is stored in and later accessed from a program variable.<\/span><\/li>\r\n<\/ul>\r\n<p class=\"c4\"><span class=\"c0\">Which method should you use?\u00a0 Refer first to any program requirements. (Does it say, \"Prompt the user to enter ...\" or \"specify as a command line argument\"?)<\/span><\/p>\r\n\r\n<\/div>\r\n<\/div>\r\n&nbsp;\r\n<h1 id=\"h.ra7wxgnr4ue\" class=\"c13 c6\"><span class=\"c10\">Quotes<\/span><\/h1>\r\n<h2 class=\"c4\"><span class=\"c0\">Single quotes:<\/span><\/h2>\r\n<p class=\"c4\"><span class=\"c0\">Problem:<\/span><\/p>\r\n\r\n<pre id=\"h.a8w4057r77np\" class=\"c4 c6\"><span class=\"c1\">$ <strong>grep Al Shaji employee_list<\/strong><\/span>\r\n<span class=\"c1\">grep: can\u2019t open Shaji<\/span><\/pre>\r\n<p class=\"c4\"><span class=\"c0\">Solution: <\/span><\/p>\r\n\r\n<pre id=\"h.c7plh3ux8g64\" class=\"c4 c6\"><span class=\"c1\">$ <strong>grep 'Al Shaji' employee_list\r\n\r\n<\/strong><\/span><\/pre>\r\nSingle quotes causes Unix to take everything within the single quotes literally.\u00a0 This is how you would prevent interpretation of characters which would normally have special meaning, for example the space character separating command line arguments.\r\n<h2 class=\"c4\"><span class=\"c0\">Double quotes<\/span><\/h2>\r\n<ul class=\"c2 lst-kix_m7najpr6q9vi-0 start\">\r\n \t<li class=\"c4 c12 c9 li-bullet-0\"><span class=\"c0\">Recognize $, \\, ` (backtick or backquote) <\/span><\/li>\r\n<\/ul>\r\n&nbsp;\r\n<div class=\"textbox textbox--exercises\"><header class=\"textbox__header\">\r\n<p class=\"textbox__title\">Exercise 1:\u00a0 Try this out and see the difference double quotes makes<\/p>\r\n\r\n<\/header>\r\n<div class=\"textbox__content\">\r\n<pre><span class=\"c1\">heading=' \u00a0 \u00a0Name \u00a0 \u00a0 Addr \u00a0 \u00a0 Phone'<\/span>\r\n<span class=\"c1\">echo $heading<\/span>\r\n<span class=\"c1\">echo \"$heading\"<\/span><\/pre>\r\n<\/div>\r\n<\/div>\r\n&nbsp;\r\n<div class=\"textbox textbox--exercises\"><header class=\"textbox__header\">\r\n<p class=\"textbox__title\">Exercise 2: <span class=\"c0\">Try this out and see the difference double quotes makes<\/span><\/p>\r\n\r\n<\/header>\r\n<div class=\"textbox__content\">\r\n<pre id=\"h.epuxcm5w1ak8\" class=\"c4 c6 c9\"><span class=\"c1\">read operator # enter asterisk *<\/span>\r\n<span class=\"c1\">echo $operator<\/span>\r\n<span class=\"c1\">echo \"$operator\"<\/span><\/pre>\r\n<\/div>\r\n<\/div>\r\n<p class=\"c3\"><span class=\"c0\">The double quotes are similar to single quotes in that Unix takes what is within the quotes literally.\u00a0 However, double quotes are \"smarter\" in that variables and selected meta-characters are interpreted and expanded in spite of the usual literal nature of quotes.\u00a0 <\/span><\/p>\r\n&nbsp;\r\n<h3 class=\"c4\"><span class=\"c0\">Home directory potential tricky issue (tilde is protected i.e. not expanded within quotes).<\/span><\/h3>\r\n<p class=\"c4\"><span class=\"c0\">Instead of:<\/span><\/p>\r\n\r\n<pre id=\"h.ebrtbg7k6if6\" class=\"c4 c6 c9\"><span class=\"c1\">datafile=\"~jasmin\/rawdata\"<\/span>\r\n<span class=\"c1\">cat $datafile \u00a0# produces \"No such file or directory\" error<\/span><\/pre>\r\n<p class=\"c4\"><span class=\"c0\">Say (solution 1):<\/span><\/p>\r\n\r\n<pre id=\"h.qgl0jf6uwsn3\" class=\"c4 c6 c9\"><span class=\"c1\">datafile=~jasmin\/rawdata<\/span>\r\n<span class=\"c1\">cat $datafile<\/span><\/pre>\r\n<p class=\"c4\"><span class=\"c0\">Say (solution 2):<\/span><\/p>\r\n\r\n<pre id=\"h.t4xu25vepjoa\" class=\"c4 c6 c9\"><span class=\"c1\">datafile=\"~jasmin\/rawdata\"<\/span>\r\n<span class=\"c1\">eval cat $datafile<\/span><\/pre>\r\n<p class=\"c3\"><span class=\"c0\">\u00a0<\/span><\/p>\r\n\r\n<h1 id=\"h.tf9sr7lgo2h5\" class=\"c6 c13\"><span class=\"c10\">Command substitution<\/span><\/h1>\r\n<p class=\"c4\">Sometimes a programmer wishes to run a command and use its output at some point within a program. \u00a0While it is possible to redirect output to a temporary file, load the contents of the file, and then promptly delete it, for small tasks, it is more convenient and efficient to use the technique of <em><span class=\"c7\">command substitution <\/span><\/em><span class=\"c0\">\u00a0and avoid extra disc access. <\/span><\/p>\r\n<p class=\"c3\"><span class=\"c0\">\u00a0<\/span><\/p>\r\n\r\n<div class=\"textbox textbox--examples\"><header class=\"textbox__header\">\r\n<p class=\"textbox__title\"><span class=\"c0\">Eg. 1 \u00a0Newbie's first guess<\/span><\/p>\r\n\r\n<\/header>\r\n<div class=\"textbox__content\">\r\n<pre id=\"h.b9wo8jyt1h4m\" class=\"c4 c6\"><span class=\"c1\">today=date<\/span>\r\n<span class=\"c1\">echo $today<\/span><\/pre>\r\n<\/div>\r\n<\/div>\r\n&nbsp;\r\n<p class=\"c3\"><span class=\"c0\">\u00a0<\/span><\/p>\r\n\r\n<div class=\"textbox textbox--examples\"><header class=\"textbox__header\">\r\n<p class=\"textbox__title\"><span class=\"c0\">Eg. 2 This is the way to do it.<\/span><\/p>\r\n\r\n<\/header>\r\n<div class=\"textbox__content\">\r\n<pre id=\"h.eiw5c4qk0n86\" class=\"c4 c6\"><span class=\"c1\">today=$(date) \u00a0(old version today=`date`)<\/span>\r\n<span class=\"c1\">echo $today<\/span><\/pre>\r\n<\/div>\r\n<\/div>\r\n&nbsp;\r\n<p class=\"c3\"><span class=\"c0\">\u00a0<\/span><\/p>\r\n\r\n<div class=\"textbox\">\r\n<p class=\"c4\"><span class=\"c0\">Syntax:<\/span><\/p>\r\n\r\n<pre id=\"h.sgrl57ij0835\" class=\"c4 c6 indent\"><span class=\"c1\">$(unix_command)<\/span><\/pre>\r\n<\/div>\r\n<p class=\"c4\"><span class=\"c0\">The mechanics of command substitution works as follows:<\/span><\/p>\r\n\r\n<ol class=\"c2 lst-kix_uh0507rs9t7n-0 start\" start=\"1\">\r\n \t<li class=\"c4 c12 c9 li-bullet-0\"><span class=\"c0\">Unix will run the command within the parentheses as if it were typed at the keyboard. \u00a0The command may include options, command line arguments, or even be a script.<\/span><\/li>\r\n \t<li class=\"c4 c12 c9 li-bullet-0\"><span class=\"c0\">Instead of being displayed on the screen, the standard output (STDOUT) of the command is substituted at the exact position of the call ($(unix_command)). \u00a0<\/span><\/li>\r\n<\/ol>\r\n<p class=\"c3\"><span class=\"c0\">\u00a0<\/span><\/p>\r\n<p class=\"c4\"><span class=\"c0\">The command substitution may be made anywhere in a program; however, it is often used on the right-hand side of an assignment statement (to save the output in a variable), or within an echo statement.<\/span><\/p>\r\n&nbsp;\r\n\r\n<span>[h5p id=\"10\"]<\/span>\r\n\r\n&nbsp;","rendered":"<h1>Shell Variables<\/h1>\n<p class=\"c4\"><span class=\"c0\">Unix is an operating system but also the name given to its scripting (programming) language. In order to be useful, a computer language needs to be able to store data. Unix supports this capability with shell variables. <\/span><\/p>\n<p class=\"c4\"><span class=\"c0\">There are three kinds of shell variables:<\/span><\/p>\n<ol class=\"c2 lst-kix_ckfao24sw02h-0 start\" start=\"1\">\n<li class=\"c4 c12 c9 li-bullet-0\"><span class=\"c0\">special<\/span><\/li>\n<li class=\"c4 c12 c9 li-bullet-0\"><span class=\"c0\">environment<\/span><\/li>\n<li class=\"c4 c12 c9 li-bullet-0\"><span class=\"c0\">program<\/span><\/li>\n<\/ol>\n<h2 id=\"h.g9x11nt2qx8t\" class=\"c13 c6\"><span class=\"c10\">Special variables<\/span><\/h2>\n<p class=\"c4\"><span class=\"c0\">Special variables are unlike what you may have seen in other programming languages. Rather special variables are created and set by the operating system automatically. Consider the following examples:<\/span><\/p>\n<p class=\"c3\"><span class=\"c0\">\u00a0<\/span><\/p>\n<h3 class=\"c5\" id=\"h.3gv6p8mlyjaa\"><span class=\"c8\">Positional parameters ($1, $2, \u2026)<\/span><\/h3>\n<p class=\"c4\"><span class=\"c0\">Recall that the cat program allows the user to specify inputs as command-line arguments:\u00a0 (In the following examples, the leading dollar sign represents the command prompt; do not type the leading dollar sign.)<\/span><\/p>\n<pre class=\"c4\"><span class=\"c0\">$ <strong>cat ch1 ch2 ch3<\/strong><\/span><\/pre>\n<p class=\"c4\"><span class=\"c0\">Imagine that you would like to write your own script allowing the user to specify inputs as command-line arguments as in. <\/span><\/p>\n<p>&nbsp;<\/p>\n<pre class=\"c4\"><span class=\"c0\">$ <strong>myscript apple cherry<\/strong><\/span><\/pre>\n<div class=\"textbox textbox--examples\">\n<header class=\"textbox__header\">\n<p class=\"textbox__title\">Example<\/p>\n<\/header>\n<div class=\"textbox__content\">\n<pre class=\"c4\"><span class=\"c1\">$ <strong>cat arg_demo<\/strong><\/span>\r\n<span class=\"c1\">#!\/bin\/bash<\/span>\r\n<span class=\"c1\">echo The 1st argument is $1<\/span>\r\n<span class=\"c1\">echo The 2nd argument is $2<\/span>\r\n$\r\n<span class=\"c1\">$ <strong>.\/arg_demo apple cherry<\/strong><\/span>\r\n<span class=\"c1\">The 1st argument is apple<\/span>\r\n<span class=\"c1\">The 2nd argument is cherry<\/span>\r\n\r\n<\/pre>\n<\/div>\n<\/div>\n<h3 class=\"c5\" id=\"h.xrhmgnq10kfz\"><span class=\"c8\">number of command line arguments ($#)<\/span><\/h3>\n<p class=\"c4\"><span class=\"c0\">The special variable $# holds the number of command-line arguments specified when your script was run.<\/span><\/p>\n<div class=\"textbox textbox--examples\">\n<header class=\"textbox__header\">\n<p class=\"textbox__title\">Examples<\/p>\n<\/header>\n<div class=\"textbox__content\">\n<pre>$ <strong>cat numeg<\/strong>\r\n<span class=\"c1\">#!\/bin\/bash\r\n<\/span><span class=\"c1\">echo The number of command line arguments is $#\r\n$\r\n$ <strong>.\/numeg apple<\/strong><\/span><strong><span class=\"c1\"> cherry\r\n<\/span><\/strong><span class=\"c1\">The number of command line arguments is 2\r\n<\/span>$<\/pre>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<h3 class=\"c5\" id=\"h.aq4mywhc5f8f\"><span class=\"c8\">return code of previous command ($?)<\/span><\/h3>\n<p class=\"c4\"><span class=\"c0\">Every Unix command generates a return code typically indicating success or failure. The value of this return code is stored in the special variable $?. Thus each time a Unix command is run the $? variable is updated automatically to hold the return code of the most recently executed Unix command. \u00a0The use of the return code is important and will become apparent in the chapter on control structures. <\/span><\/p>\n<h2 class=\"c13 c6\"><span class=\"c10\">Environment <\/span><span class=\"c10\">variables<\/span><\/h2>\n<p class=\"c4\"><span class=\"c0\">Environment variables hold information about the users&#8217;s current settings and configuration. By convention, they are typically all UPPERCASE. To display them, type \u2018env\u2019<\/span><\/p>\n<div class=\"textbox textbox--examples\">\n<header class=\"textbox__header\">\n<p class=\"textbox__title\">Example<\/p>\n<\/header>\n<div class=\"textbox__content\">\n<pre class=\"c3\"><span class=\"c0\">lhiraki@metis:~$ <strong>env<\/strong>\r\nSHELL=\/bin\/bash\r\nPATH=\/usr\/local\/bin:\/usr\/bin:\/bin:\/usr\/local\/games:\/usr\/games:\/snap\/bin:\/usr\/courses\/bin\/x86_64\r\nJAVA_HOME=\/usr\/lib\/jvm\/java-8-openjdk-amd64\r\nEDITOR=vi\r\nLANGUAGE=en_CA:en\r\nLPDEST=eng206c\r\nlhiraki@metis:~$\r\n<\/span><\/pre>\n<p>Here is an abridged list of environment variables.\u00a0 Some of the typical environment variables include SHELL (current shell), PATH (list of directories the operating system will search in order to find a command), EDITOR (preferred editor), LANGUAGE (preferred display language), LPDEST (preferred printer destination).<\/p>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<h2 class=\"c5\"><span class=\"c8\">Program <\/span><span class=\"c10\">variables<\/span><\/h2>\n<p class=\"c4\"><span class=\"c0\">Program variables are the type of variable that typically come to mind when one thinks of variables in a computer programming language. Program variables are variables which you as the programmer create and set. As Unix is a prototyping language, it is common to dispense with many of the formalities required for variable declarations, etc. <\/span><\/p>\n<p class=\"c3\"><span class=\"c0\">\u00a0<\/span><\/p>\n<p class=\"c4\"><span class=\"c0\">Program variables hold a string, i.e. text, and can be used anywhere text could appear in a program such as a filename, part of the file name, or even a Unix command itself. \u00a0A variable can hold only one value at a time. <\/span><\/p>\n<p class=\"c3\"><span class=\"c0\">\u00a0<\/span><\/p>\n<p class=\"c4\"><span class=\"c0\">The naming convention for program variables is to use lowercase. Specifically uppercase program variable names should be avoided so as to prevent confusion with environment variables and accidentally overwriting an environment variable.<\/span><\/p>\n<p class=\"c3\"><span class=\"c0\">\u00a0<\/span><\/p>\n<p class=\"c3\"><span class=\"c0\">\u00a0<\/span><\/p>\n<p class=\"c3\"><span class=\"c0\">\u00a0<\/span><\/p>\n<div class=\"textbox textbox--examples\">\n<header class=\"textbox__header\">\n<p class=\"textbox__title\"><span class=\"c0\">Eg. 1 \u00a0An easy way to create and set a program variable is using an assignment statement.<\/span><\/p>\n<\/header>\n<div class=\"textbox__content\">\n<pre id=\"h.7cl5azn9o175\" class=\"c4 c6\"><span class=\"c1\">temp_name=\/usr\/temp<\/span>\r\n<span class=\"c1\">cp myfile $temp_name<\/span><\/pre>\n<\/div>\n<\/div>\n<p class=\"c3\"><span class=\"c0\">\u00a0<\/span><\/p>\n<p class=\"c4\"><span class=\"c0\">Assignment statements copy the value to the right of the equal sign to the variable on the left. \u00a0Important: \u00a0Assignment statements must not contain spaces, especially around the equal sign.<\/span><\/p>\n<p class=\"c3\"><span class=\"c0\">\u00a0<\/span><\/p>\n<div class=\"textbox textbox--examples\">\n<header class=\"textbox__header\">\n<p class=\"textbox__title\">Eg. 2<\/p>\n<\/header>\n<div class=\"textbox__content\">\n<pre id=\"h.swweyesv5zvn\" class=\"c4 c6\"><span class=\"c1\">month=september <\/span>\r\n<span class=\"c1\">echo the current month is $month<\/span><\/pre>\n<\/div>\n<\/div>\n<h3 class=\"c5\" id=\"h.hzz5ibquuoql\"><span class=\"c8\">When to use $ with variables<\/span><\/h3>\n<p class=\"c4\"><span class=\"c0\">When writing to a variable, i.e. setting or changing its contents, do not use the dollar sign. When reading a variable, i.e. accessing its contents, you must use the dollar sign.<\/span><\/p>\n<p class=\"c3\"><span class=\"c0\">\u00a0<\/span><\/p>\n<div class=\"textbox textbox--key-takeaways\">\n<header class=\"textbox__header\">\n<p class=\"textbox__title\">Key Takeaway &#8211; <span class=\"c0\">When to use $ with variables:<\/span><\/p>\n<\/header>\n<div class=\"textbox__content\">\n<p class=\"c4\"><span class=\"c0\"><strong>Writing<\/strong> to a variable: <strong>no<\/strong> dollar sign<\/span><\/p>\n<p class=\"c4\"><span class=\"c0\"><strong>Reading<\/strong> from a variable: <strong>use<\/strong> dollar sign<\/span><\/p>\n<\/div>\n<\/div>\n<div class=\"textbox shaded\">\n<p class=\"c3\">Editorial Remark:<\/p>\n<p>One of the key factors affected software maintenance costs is code readability.\u00a0 Most of the time (cost) of maintaining software is spent in having designers read and understand existing code.\u00a0 One way to control and reduce costs (business competitiveness) is to ease readability.\u00a0 By choosing variables which reflect their contents, it makes it easier to understand the code.<\/p>\n<p class=\"c4\"><strong><span class=\"c0\">Choose self-describing variable names:<\/span><\/strong><\/p>\n<table class=\"grid\" style=\"border-collapse: collapse;width: 100%;height: 30px\">\n<thead>\n<tr style=\"height: 15px\">\n<th style=\"width: 50%;height: 15px\" scope=\"col\"><span style=\"font-size: 16px\">Good variable names:<\/span><\/th>\n<th style=\"width: 50%;height: 15px\" scope=\"col\"><span class=\"c0\">Bad variable names:<\/span><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr style=\"height: 15px\">\n<td style=\"width: 50%;height: 15px\">\n<ul class=\"c2 lst-kix_furawtezqk8i-0 start\">\n<li class=\"c4 c12 c9 li-bullet-0\"><span class=\"c0\">sum <\/span><\/li>\n<li class=\"c4 c12 c9 li-bullet-0\"><span class=\"c0\">total<\/span><\/li>\n<li class=\"c4 c12 c9 li-bullet-0\"><span class=\"c0\">x_value<\/span><\/li>\n<li class=\"c4 c12 c9 li-bullet-0\"><span class=\"c0\">length <\/span><\/li>\n<li class=\"c4 c12 c9 li-bullet-0\"><span class=\"c0\">count<\/span><\/li>\n<\/ul>\n<\/td>\n<td style=\"width: 50%;height: 15px\">\n<ul class=\"c2 lst-kix_14tmntyk4v1-0 start\">\n<li class=\"c4 c12 c9 li-bullet-0\"><span class=\"c0\">a,b,c\u2026.<\/span><\/li>\n<li class=\"c4 c12 c9 li-bullet-0\"><span class=\"c0\">var1, var2, var3\u2026.<\/span><\/li>\n<\/ul>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"text-align: initial;font-size: 1em\">\u00a0<\/span><\/p>\n<\/div>\n<h1 id=\"h.1bkln71pd17i\" class=\"c13 c6\"><span class=\"c10\">read<\/span><\/h1>\n<p class=\"c4\"><span class=\"c0\">The read command collects characters from standard input (STDIN) and stores them in a variable. \u00a0The read command is typically used in an interactive script to collect user input after an appropriate prompt message. \u00a0As the read command draws from standard input, and standard input can be redirected from a file, it is possible to prepare inputs (answers) in a file and run the script in a non-interactive fashion.<\/span><\/p>\n<p class=\"c3\"><span class=\"c0\">\u00a0<\/span><\/p>\n<div class=\"textbox textbox--examples\">\n<header class=\"textbox__header\">\n<p class=\"textbox__title\">Example using read command<\/p>\n<\/header>\n<div class=\"textbox__content\">\n<pre id=\"h.3pe0qxhk8bnw\" class=\"c4 c6\"><span class=\"c1\">$ <strong>cat readeg<\/strong><\/span>\r\n<span class=\"c1\">echo -n 'What is your name? '<\/span>\r\n<span class=\"c1\">read name<\/span>\r\n<span class=\"c1\">echo Hello $name, pleased to meet you!<\/span>\r\n<span class=\"c1\">$<\/span>\r\n<span class=\"c1\">$ <strong>.\/readeg<\/strong><\/span>\r\n<span class=\"c1\">What is your name? <strong>Mohammed<\/strong><\/span>\r\n<span class=\"c1\">Hello Mohammed, pleased to meet you!<\/span>\r\n<span class=\"c1\">$<\/span><\/pre>\n<\/div>\n<\/div>\n<div class=\"textbox shaded\">\n<p>What does the option &#8220;-n&#8221; do in the echo command above?<\/p>\n<p>Hint: type &#8220;man echo&#8221;.\u00a0 To exit the manual, press &#8220;q&#8221;.<\/p>\n<\/div>\n<div><\/div>\n<div class=\"textbox textbox--key-takeaways\">\n<header class=\"textbox__header\">\n<p class=\"textbox__title\">Key Takeaways<\/p>\n<\/header>\n<div class=\"textbox__content\">\n<p class=\"c4\"><span class=\"c0\">read vs. command line arguments<\/span><\/p>\n<ul>\n<li class=\"c4\"><span class=\"c0\">Both are ways the user can supply input to a program.\u00a0 Command line arguments are placed on the command line before pressing &lt;ENTER&gt; to run the program.\u00a0 The values are accessed within one&#8217;s program using $1, $2, etc.<\/span><\/li>\n<li class=\"c4\"><span class=\"c0\">The &#8220;read&#8221; command causes the program to wait for keyboard input (if STDIN has not been redirected from a file).\u00a0 The input is stored in and later accessed from a program variable.<\/span><\/li>\n<\/ul>\n<p class=\"c4\"><span class=\"c0\">Which method should you use?\u00a0 Refer first to any program requirements. (Does it say, &#8220;Prompt the user to enter &#8230;&#8221; or &#8220;specify as a command line argument&#8221;?)<\/span><\/p>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<h1 id=\"h.ra7wxgnr4ue\" class=\"c13 c6\"><span class=\"c10\">Quotes<\/span><\/h1>\n<h2 class=\"c4\"><span class=\"c0\">Single quotes:<\/span><\/h2>\n<p class=\"c4\"><span class=\"c0\">Problem:<\/span><\/p>\n<pre id=\"h.a8w4057r77np\" class=\"c4 c6\"><span class=\"c1\">$ <strong>grep Al Shaji employee_list<\/strong><\/span>\r\n<span class=\"c1\">grep: can\u2019t open Shaji<\/span><\/pre>\n<p class=\"c4\"><span class=\"c0\">Solution: <\/span><\/p>\n<pre id=\"h.c7plh3ux8g64\" class=\"c4 c6\"><span class=\"c1\">$ <strong>grep 'Al Shaji' employee_list\r\n\r\n<\/strong><\/span><\/pre>\n<p>Single quotes causes Unix to take everything within the single quotes literally.\u00a0 This is how you would prevent interpretation of characters which would normally have special meaning, for example the space character separating command line arguments.<\/p>\n<h2 class=\"c4\"><span class=\"c0\">Double quotes<\/span><\/h2>\n<ul class=\"c2 lst-kix_m7najpr6q9vi-0 start\">\n<li class=\"c4 c12 c9 li-bullet-0\"><span class=\"c0\">Recognize $, \\, ` (backtick or backquote) <\/span><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<div class=\"textbox textbox--exercises\">\n<header class=\"textbox__header\">\n<p class=\"textbox__title\">Exercise 1:\u00a0 Try this out and see the difference double quotes makes<\/p>\n<\/header>\n<div class=\"textbox__content\">\n<pre><span class=\"c1\">heading=' \u00a0 \u00a0Name \u00a0 \u00a0 Addr \u00a0 \u00a0 Phone'<\/span>\r\n<span class=\"c1\">echo $heading<\/span>\r\n<span class=\"c1\">echo \"$heading\"<\/span><\/pre>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<div class=\"textbox textbox--exercises\">\n<header class=\"textbox__header\">\n<p class=\"textbox__title\">Exercise 2: <span class=\"c0\">Try this out and see the difference double quotes makes<\/span><\/p>\n<\/header>\n<div class=\"textbox__content\">\n<pre id=\"h.epuxcm5w1ak8\" class=\"c4 c6 c9\"><span class=\"c1\">read operator # enter asterisk *<\/span>\r\n<span class=\"c1\">echo $operator<\/span>\r\n<span class=\"c1\">echo \"$operator\"<\/span><\/pre>\n<\/div>\n<\/div>\n<p class=\"c3\"><span class=\"c0\">The double quotes are similar to single quotes in that Unix takes what is within the quotes literally.\u00a0 However, double quotes are &#8220;smarter&#8221; in that variables and selected meta-characters are interpreted and expanded in spite of the usual literal nature of quotes.\u00a0 <\/span><\/p>\n<p>&nbsp;<\/p>\n<h3 class=\"c4\"><span class=\"c0\">Home directory potential tricky issue (tilde is protected i.e. not expanded within quotes).<\/span><\/h3>\n<p class=\"c4\"><span class=\"c0\">Instead of:<\/span><\/p>\n<pre id=\"h.ebrtbg7k6if6\" class=\"c4 c6 c9\"><span class=\"c1\">datafile=\"~jasmin\/rawdata\"<\/span>\r\n<span class=\"c1\">cat $datafile \u00a0# produces \"No such file or directory\" error<\/span><\/pre>\n<p class=\"c4\"><span class=\"c0\">Say (solution 1):<\/span><\/p>\n<pre id=\"h.qgl0jf6uwsn3\" class=\"c4 c6 c9\"><span class=\"c1\">datafile=~jasmin\/rawdata<\/span>\r\n<span class=\"c1\">cat $datafile<\/span><\/pre>\n<p class=\"c4\"><span class=\"c0\">Say (solution 2):<\/span><\/p>\n<pre id=\"h.t4xu25vepjoa\" class=\"c4 c6 c9\"><span class=\"c1\">datafile=\"~jasmin\/rawdata\"<\/span>\r\n<span class=\"c1\">eval cat $datafile<\/span><\/pre>\n<p class=\"c3\"><span class=\"c0\">\u00a0<\/span><\/p>\n<h1 id=\"h.tf9sr7lgo2h5\" class=\"c6 c13\"><span class=\"c10\">Command substitution<\/span><\/h1>\n<p class=\"c4\">Sometimes a programmer wishes to run a command and use its output at some point within a program. \u00a0While it is possible to redirect output to a temporary file, load the contents of the file, and then promptly delete it, for small tasks, it is more convenient and efficient to use the technique of <em><span class=\"c7\">command substitution <\/span><\/em><span class=\"c0\">\u00a0and avoid extra disc access. <\/span><\/p>\n<p class=\"c3\"><span class=\"c0\">\u00a0<\/span><\/p>\n<div class=\"textbox textbox--examples\">\n<header class=\"textbox__header\">\n<p class=\"textbox__title\"><span class=\"c0\">Eg. 1 \u00a0Newbie&#8217;s first guess<\/span><\/p>\n<\/header>\n<div class=\"textbox__content\">\n<pre id=\"h.b9wo8jyt1h4m\" class=\"c4 c6\"><span class=\"c1\">today=date<\/span>\r\n<span class=\"c1\">echo $today<\/span><\/pre>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<p class=\"c3\"><span class=\"c0\">\u00a0<\/span><\/p>\n<div class=\"textbox textbox--examples\">\n<header class=\"textbox__header\">\n<p class=\"textbox__title\"><span class=\"c0\">Eg. 2 This is the way to do it.<\/span><\/p>\n<\/header>\n<div class=\"textbox__content\">\n<pre id=\"h.eiw5c4qk0n86\" class=\"c4 c6\"><span class=\"c1\">today=$(date) \u00a0(old version today=`date`)<\/span>\r\n<span class=\"c1\">echo $today<\/span><\/pre>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<p class=\"c3\"><span class=\"c0\">\u00a0<\/span><\/p>\n<div class=\"textbox\">\n<p class=\"c4\"><span class=\"c0\">Syntax:<\/span><\/p>\n<pre id=\"h.sgrl57ij0835\" class=\"c4 c6 indent\"><span class=\"c1\">$(unix_command)<\/span><\/pre>\n<\/div>\n<p class=\"c4\"><span class=\"c0\">The mechanics of command substitution works as follows:<\/span><\/p>\n<ol class=\"c2 lst-kix_uh0507rs9t7n-0 start\" start=\"1\">\n<li class=\"c4 c12 c9 li-bullet-0\"><span class=\"c0\">Unix will run the command within the parentheses as if it were typed at the keyboard. \u00a0The command may include options, command line arguments, or even be a script.<\/span><\/li>\n<li class=\"c4 c12 c9 li-bullet-0\"><span class=\"c0\">Instead of being displayed on the screen, the standard output (STDOUT) of the command is substituted at the exact position of the call ($(unix_command)). \u00a0<\/span><\/li>\n<\/ol>\n<p class=\"c3\"><span class=\"c0\">\u00a0<\/span><\/p>\n<p class=\"c4\"><span class=\"c0\">The command substitution may be made anywhere in a program; however, it is often used on the right-hand side of an assignment statement (to save the output in a variable), or within an echo statement.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span><\/p>\n<div id=\"h5p-10\">\n<div class=\"h5p-iframe-wrapper\"><iframe id=\"h5p-iframe-10\" class=\"h5p-iframe\" data-content-id=\"10\" style=\"height:1px\" src=\"about:blank\" frameBorder=\"0\" scrolling=\"no\" title=\"Unix cmd sub to var\"><\/iframe><\/div>\n<\/div>\n<p><\/span><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"author":2,"menu_order":4,"template":"","meta":{"pb_show_title":"on","pb_short_title":"","pb_subtitle":"","pb_authors":[],"pb_section_license":""},"chapter-type":[],"contributor":[],"license":[],"class_list":["post-35","chapter","type-chapter","status-publish","hentry"],"part":23,"_links":{"self":[{"href":"https:\/\/pressbooks.library.torontomu.ca\/opsyshiraki\/wp-json\/pressbooks\/v2\/chapters\/35","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":4,"href":"https:\/\/pressbooks.library.torontomu.ca\/opsyshiraki\/wp-json\/pressbooks\/v2\/chapters\/35\/revisions"}],"predecessor-version":[{"id":76,"href":"https:\/\/pressbooks.library.torontomu.ca\/opsyshiraki\/wp-json\/pressbooks\/v2\/chapters\/35\/revisions\/76"}],"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\/35\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/pressbooks.library.torontomu.ca\/opsyshiraki\/wp-json\/wp\/v2\/media?parent=35"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/pressbooks.library.torontomu.ca\/opsyshiraki\/wp-json\/pressbooks\/v2\/chapter-type?post=35"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/pressbooks.library.torontomu.ca\/opsyshiraki\/wp-json\/wp\/v2\/contributor?post=35"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/pressbooks.library.torontomu.ca\/opsyshiraki\/wp-json\/wp\/v2\/license?post=35"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}