{"id":17540,"date":"2022-03-24T17:25:42","date_gmt":"2022-03-24T11:55:42","guid":{"rendered":"https:\/\/www.hexnode.com\/blogs\/?p=17540"},"modified":"2023-05-31T16:50:53","modified_gmt":"2023-05-31T11:20:53","slug":"the-ultimate-guide-to-mac-shell-scripting","status":"publish","type":"post","link":"https:\/\/www.hexnode.com\/blogs\/the-ultimate-guide-to-mac-shell-scripting\/","title":{"rendered":"The ultimate guide to Mac shell scripting"},"content":{"rendered":"<p>Is <strong>Mac shell scripting<\/strong> difficult to learn?<\/p>\n<p>Well, to be honest, it depends. Shell scripting can prove to be quite challenging for individuals who do not have a firm grasp of its pre-requisites. However, learning the fundamentals of shell programming is actually rather simple.<\/p>\n<p>The reason you may be facing difficulties with Mac shell scripting might be due to either of these reasons:<\/p>\n<ul>\n<li>You may need more experience in <strong>programming<\/strong> and in solving problems using <strong>logic<\/strong>.<\/li>\n<li>You may need more knowledge in the multitude of <strong>commands available<\/strong> for Mac shell scripting.<\/li>\n<\/ul>\n<p>It&#8217;s tough to put tools together in a script if you don&#8217;t know how to utilize them individually or even know what problems they answer.<\/p>\n<p>But do not despair, as there is hope. For this is precisely what we aim to remedy with this blog.<\/p>\n<p>In this beginner-friendly guide,<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>We\u2019re going to walk you through the basics of Mac shell scripting, including how to <strong>create<\/strong> and <strong>run<\/strong> a Shell script.<\/li>\n<li>We\u2019ll explore some of the basic Mac shell scripting <strong>terms<\/strong> and <strong>commands<\/strong>.<\/li>\n<li>We shall review some of the <strong>applications<\/strong>, <strong>use-cases<\/strong>, and <strong>best practices<\/strong> for Mac Shell scripting.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>When you\u2019re done with this guide, we expect you to be equipped with all the information and pre-requisites you may require to begin your own shell scripting journey.<\/p>\n<p><center>    \t\t<!-- button style scb20be917a3efc78059cf9961ee4e54284 -->\r\n    \t\t<style>\r\n    \t\t\t.scb20be917a3efc78059cf9961ee4e54284, a.scb20be917a3efc78059cf9961ee4e54284{\r\n    \t\t\t\tcolor: #fff;\r\n    \t\t\t\tbackground-color: #00868B;\r\n    \t\t\t}\r\n    \t\t\t.scb20be917a3efc78059cf9961ee4e54284:hover, a.scb20be917a3efc78059cf9961ee4e54284:hover{\r\n    \t\t\t\t    \t\t\t\tbackground-color: #32b8bd;\r\n    \t\t\t}\r\n    \t\t<\/style>\r\n    \t\t<a href=\"https:\/\/www.hexnode.com\/uem\/solution\/mdm\/?utm_source=hexnode_blog_mac_shell_scripting&amp;utm_medium=referral&amp;utm_campaign=button\" class=\"ht-shortcodes-button scb20be917a3efc78059cf9961ee4e54284  hn-cta__blogs--inline-button \" id=\"\" style=\"\" target=\"_blank\">\r\n    \t\tDeploy Mac shell scripts with ease using Hexnode UEM<\/a>\r\n    \t\t<\/center><\/p>\n<h2>What are shell scripts?<\/h2>\n<p><center><a href=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/IT-technician-running-scripts-on-a-Mac.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" class=\"\" src=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/IT-technician-running-scripts-on-a-Mac.png\" alt=\"IT technician running scripts on a Mac\" width=\"682\" height=\"425\" \/><\/a><\/center><center><em>IT technician running scripts on a Mac<\/em><\/center>&nbsp;<\/p>\n<p>Shell scripts are text files or small computer programs that consist of a <strong>collection of UNIX commands<\/strong>. You use a shell script to execute commands that you would normally type on the command line. However, rather than inputting them one by one into a Mac&#8217;s terminal, you can use shell scripts to execute the said group of commands with just one single action.<\/p>\n<h3>Why use Mac shell scripts?<\/h3>\n<p>While Mac shell scripts aren&#8217;t generally used to create complex programs and functions, you can use them to <a href=\"https:\/\/www.hexnode.com\/mobile-device-management\/help\/register\/?videoid=Mzk3Mjk=&amp;utm_source=hexnode_blog_mac_shell_scripting&amp;utm_medium=referral&amp;utm_campaign=internal_link\" target=\"_blank\" rel=\"noopener\">automate most of the basic software operations<\/a>. With the help of its powerful built-in command-line tools, you can create scripts to perform operations such as:<\/p>\n    \t\t<div class=\"hts-toggle  \"  >\r\n    \t\t\t<div class=\"hts-toggle__title\">Accessing and navigating your operating system more efficiently<\/div>\r\n    \t\t\t<div class=\"hts-toggle__content\">\r\n    \t\t\t\t<div class=\"hts-toggle__contentwrap\">\r\n    \t\t\t\t\t<p>With the help of scripting commands, you can navigate through your computer&#8217;s OS without having to interact with the GUI. This eliminates the need to go through your Mac&#8217;s menus, options, and windows.<\/p>\n<p>Moreover, when combined with the remoting functionality via SSH, scripting allows IT to perform remote operations and processes on macOS devices.<\/p>\n    \t\t\t\t<\/div>\r\n    \t\t\t<\/div><!-- \/ht-toggle-content -->\r\n    \t\t<\/div>\r\n    \t\t\n    \t\t<div class=\"hts-toggle  \"  >\r\n    \t\t\t<div class=\"hts-toggle__title\">Creating and editing text files, searching files within directories<\/div>\r\n    \t\t\t<div class=\"hts-toggle__content\">\r\n    \t\t\t\t<div class=\"hts-toggle__contentwrap\">\r\n    \t\t\t\t\t<p>With the help of macOS scripts, you can easily create and edit text files, and perform actions such as,<\/p>\n<ul>\n<li>Preparing data<\/li>\n<li>Sorting and editing data<\/li>\n<li>Searching for specific texts within data<\/li>\n<li>Looking up files within a directory<\/li>\n<\/ul>\n<p>\n    \t\t\t\t<\/div>\r\n    \t\t\t<\/div><!-- \/ht-toggle-content -->\r\n    \t\t<\/div>\r\n    \t\t\n    \t\t<div class=\"hts-toggle  \"  >\r\n    \t\t\t<div class=\"hts-toggle__title\">Integrate with other powerful tools that are installed<\/div>\r\n    \t\t\t<div class=\"hts-toggle__content\">\r\n    \t\t\t\t<div class=\"hts-toggle__contentwrap\">\r\n    \t\t\t\t\t<p>Mac shell scripting is ideal for integrating and connecting with other powerful tools within your system. As Apple says in their <a href=\"https:\/\/developer.apple.com\/library\/archive\/documentation\/OpenSource\/Conceptual\/ShellScripting\/Introduction\/Introduction.html\" target=\"_blank\" rel=\"noopener noreferrer nofollow\">Mac shell scripting primer<\/a>,<\/p>\n<blockquote>\n<p>&#8220;Shell scripting is generally considered to be a glue language, ideal for creating small pieces of code that connect other tools together. \u201c<\/p>\n<\/blockquote>\n<p>\n    \t\t\t\t<\/div>\r\n    \t\t\t<\/div><!-- \/ht-toggle-content -->\r\n    \t\t<\/div>\r\n    \t\t\n<p>They also allow for more practical functions, such as piping or command substitution. You can utilize the result of a command, and use its output as part of your next command.<\/p>\n<p>Moreover, shell scripts allow you to use programming operations such as \u2018for\u2019 loops, if\/then\/else statements, and more, directly within the command-line. And the best part? You don\u2019t have to learn an entire new programming language as Mac shell scripting works on the good ol\u2019 terminal commands.<\/p>\n<h3>Terminal commands vs shell scripts \u2013 What&#8217;s the difference?<\/h3>\n<p>Terminal is the name given to the macOS <strong>command-line interface (CLI)<\/strong>. It enables users to input single-line, text-based commands that help perform system-level operations on the device.<\/p>\n<p>Shell scripts, on the other hand, are computer programs that collect a series of terminal commands into one file. While typing commands into the Terminal is done one by one, you can execute scripts with a collection of commands with just one click. This makes it easier to execute repeating or multi-process operations while eliminating any element of human error.<\/p>\n<h2>What are shells?<\/h2>\n<p><center><a href=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/Reviewing-shell-scripts-on-a-Mac.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" class=\"\" src=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/Reviewing-shell-scripts-on-a-Mac.png\" alt=\"ZReviewing shell scripts on a Mac\" width=\"682\" height=\"425\" \/><\/a><\/center><center><em>Reviewing shell scripts on a Mac<\/em><\/center>&nbsp;<\/p>\n<p>A shell is a special <strong>command-line interpreter<\/strong> that allows you to interact with the system kernel through issuing commands. To put it simply, a shell takes your text-based commands, converts them into programmable language and delivers it to the operating system to put into action.<\/p>\n<p>Mac&#8217;s default shell is either zsh <em>(Z shell)<\/em> or bash <em>(Bourne-again Shell)<\/em>. This default shell is determined by the version of macOS you&#8217;re running.<\/p>\n<ul>\n<li>For macOS Mojave and earlier, the default shell is<strong> bash<\/strong>.<\/li>\n<li>For macOS Catalina and later, the default shell is <strong>zsh<\/strong>.<\/li>\n<\/ul>\n<h3>Bash vs Zsh \u2013 What&#8217;s the difference?<\/h3>\n<p>So, what\u2019s the difference between zsh <em>(Z shell)<\/em> and bash <em>(Bourne-again Shell)<\/em>?<\/p>\n<p>Not much, really. Both bash and zsh are part of the Bourne family of shells, and have most of the fundamental features in common. However, some minor differences do exist between both shells.<\/p>\n<table style=\"font-weight: 400; width: 100%; height: 288px;\" data-tablestyle=\"MsoTableGrid\" data-tablelook=\"1696\" aria-rowcount=\"5\">\n<tbody>\n<tr style=\"height: 24px;\" aria-rowindex=\"1\">\n<td style=\"text-align: center; height: 24px;\" data-celllook=\"4369\"><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:2,&quot;335551620&quot;:2,&quot;335559740&quot;:259}\">\u00a0<\/span><\/td>\n<td style=\"text-align: center; height: 24px;\" data-celllook=\"4369\"><b>BASH<\/b><\/td>\n<td style=\"text-align: center; height: 24px;\" data-celllook=\"4369\"><b><span data-contrast=\"auto\">ZSH<\/span><\/b><\/td>\n<\/tr>\n<tr style=\"height: 96px;\" aria-rowindex=\"2\">\n<td style=\"text-align: center; height: 96px;\" data-celllook=\"4369\"><b><span data-contrast=\"auto\">Directory navigation<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:2,&quot;335551620&quot;:2,&quot;335559740&quot;:259}\">\u00a0<\/span><\/td>\n<td style=\"text-align: center; height: 96px;\" data-celllook=\"4369\"><span data-contrast=\"auto\">Directory navigation in bash is relatively more difficult, as it does not support recursive path expansion. You will have to type the full path of the directory during file navigation.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:2,&quot;335551620&quot;:2,&quot;335559740&quot;:259}\">\u00a0<\/span><\/td>\n<td style=\"text-align: center; height: 96px;\" data-celllook=\"4369\"><span data-contrast=\"auto\">Searching directories and files in zsh is relatively easier, as it supports recursive path expansion. For example, if you type in cd myfile in zsh, it will search any file or folder whose name has myfile.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:2,&quot;335551620&quot;:2,&quot;335559740&quot;:259}\">\u00a0<\/span><\/td>\n<\/tr>\n<tr style=\"height: 72px;\" aria-rowindex=\"3\">\n<td style=\"text-align: center; height: 72px;\" data-celllook=\"4369\"><b><span data-contrast=\"auto\">Spelling auto-correction<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:2,&quot;335551620&quot;:2,&quot;335559740&quot;:259}\">\u00a0<\/span><\/td>\n<td style=\"text-align: center; height: 72px;\" data-celllook=\"4369\"><span data-contrast=\"auto\">Although you can manually enable spelling auto-correction, it is not enabled by default and is not as efficient as in zsh.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:2,&quot;335551620&quot;:2,&quot;335559740&quot;:259}\">\u00a0<\/span><\/td>\n<td style=\"text-align: center; height: 72px;\" data-celllook=\"4369\"><span data-contrast=\"auto\">Spelling auto-correction is more efficient and functional in zsh. However, it is not enabled by default.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:2,&quot;335551620&quot;:2,&quot;335559740&quot;:259}\">\u00a0<\/span><\/td>\n<\/tr>\n<tr style=\"height: 48px;\" aria-rowindex=\"4\">\n<td style=\"text-align: center; height: 48px;\" data-celllook=\"4369\"><b><span data-contrast=\"auto\">Wildcard expansion<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:2,&quot;335551620&quot;:2,&quot;335559740&quot;:259}\">\u00a0<\/span><\/td>\n<td style=\"text-align: center; height: 48px;\" data-celllook=\"4369\"><span data-contrast=\"auto\">Wildcard expansion is enabled by default in bash.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:2,&quot;335551620&quot;:2,&quot;335559740&quot;:259}\">\u00a0<\/span><\/td>\n<td style=\"text-align: center; height: 48px;\" data-celllook=\"4369\"><span data-contrast=\"auto\">Wildcard expansion is not enabled by default in zsh.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:2,&quot;335551620&quot;:2,&quot;335559740&quot;:259}\">\u00a0<\/span><\/td>\n<\/tr>\n<tr style=\"height: 48px;\" aria-rowindex=\"5\">\n<td style=\"text-align: center; height: 48px;\" data-celllook=\"4369\"><b><span data-contrast=\"auto\">Theme customization<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:2,&quot;335551620&quot;:2,&quot;335559740&quot;:259}\">\u00a0<\/span><\/td>\n<td style=\"text-align: center; height: 48px;\" data-celllook=\"4369\"><span data-contrast=\"auto\">Zsh offers many themes and plugins.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:2,&quot;335551620&quot;:2,&quot;335559740&quot;:259}\">\u00a0<\/span><\/td>\n<td style=\"text-align: center; height: 48px;\" data-celllook=\"4369\"><span data-contrast=\"auto\">Bash offers relatively less themes and plugins.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:2,&quot;335551620&quot;:2,&quot;335559740&quot;:259}\">\u00a0<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Moreover, bash is more widely used among IT administrators, and has more resources and help documentation. Hence, it is a great option for beginners. On the other hand, zsh offers extensibility, good customization, and unique functionalities. Choosing the right shell would depend mostly on user preference.<\/p>\n<p><em><strong>The programs included in this guide have been performed on the bash shell.<\/strong><\/em><\/p>\n<h3>How do I change the default shell on my Mac?<\/h3>\n<p>Alright, so let\u2019s look at how you can change the default shell on your macOS device. There are two ways to go about with this.<\/p>\n    \t\t<div class=\"hts-toggle  \"  >\r\n    \t\t\t<div class=\"hts-toggle__title\">From System Preferences<\/div>\r\n    \t\t\t<div class=\"hts-toggle__content\">\r\n    \t\t\t\t<div class=\"hts-toggle__contentwrap\">\r\n    \t\t\t\t\t<p>Option one, is to change the default shell from <em><strong>System Preferences<\/strong><\/em> on your Mac.<\/p>\n<ul>\n<li>Open <em><strong>System Preferences<\/strong><\/em> and navigate to <em><strong>Users &amp; Groups<\/strong><\/em>.<\/li>\n<li>Click on the <em><strong>Lock<\/strong><\/em> icon and enter your username and password <em>(must have admin privileges<\/em>).<\/li>\n<li>Now, hold down the <strong>ctrl<\/strong> button on your Mac keyboard and click on your username. A dropdown appears.<\/li>\n<li>Click on <strong>Advanced options<\/strong>. On the tab that appears, expand the dropdown for <strong>Login Shell<\/strong> and choose your preferred shell.<\/li>\n<\/ul>\n<p><center><a href=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/Changing-your-Macs-default-shell-via-System-Preferences.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" class=\"\" src=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/Changing-your-Macs-default-shell-via-System-Preferences.png\" alt=\"Changing your Mac's default shell via System Preferences\" width=\"682\" height=\"425\" \/><\/a><\/center><center><em>Changing your Mac&#8217;s default shell via System Preferences<\/em><\/center><br \/>\nYou have successfully changed the default shell on your Mac.<\/p>\n<p>\n    \t\t\t\t<\/div>\r\n    \t\t\t<\/div><!-- \/ht-toggle-content -->\r\n    \t\t<\/div>\r\n    \t\t\n    \t\t<div class=\"hts-toggle  \"  >\r\n    \t\t\t<div class=\"hts-toggle__title\">Using terminal commands<\/div>\r\n    \t\t\t<div class=\"hts-toggle__content\">\r\n    \t\t\t\t<div class=\"hts-toggle__contentwrap\">\r\n    \t\t\t\t\t<p>Option two, is to change the default shell using terminal commands.<\/p>\n<ul>\n<li>Open the terminal on your Mac and enter the command<\/li>\n<\/ul>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true\" title=\"Command to show all available shells for your Mac\">cat \/etc\/shells<\/pre>\n<\/div>\n<ul>\n<li>This command shows all the available shells for your Mac.<\/li>\n<li>Now, once you\u2019ve decided on your shell, enter the following command<\/li>\n<\/ul>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Command to change the default shell on your Mac\">chsh -s (shell syntax, obtained from the previous command)<\/pre>\n<\/div>\n<ul>\n<li>For example,<\/li>\n<\/ul>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Command to change the default shell on your Mac to bash\">chsh -s \/bin\/bash<\/pre>\n<\/div>\n<ul>\n<li>Next enter the password for your user account to confirm.<\/li>\n<\/ul>\n<p><em>When entering the password after the prompt appears, you will not see anything appear in the Terminal window. So the question pops up, how will you know if you\u2019ve hit the right password? Well, once you\u2019ve typed in your password and pressed \u2018Enter\u2019, you will see the message &#8220;Sorry, try again&#8221; if the password is entered incorrectly.<\/em><\/p>\n<p><center><a href=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/Changing-your-Macs-default-shell-using-Terminal-commands.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" class=\"\" src=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/Changing-your-Macs-default-shell-using-Terminal-commands.png\" alt=\"Changing your Mac's default shell using Terminal commands\" width=\"682\" height=\"425\" \/><\/a><\/center><center><em>Changing your Mac&#8217;s default shell using Terminal commands<\/em><\/center><br \/>\nYou have successfully changed the default shell on your Mac.<\/p>\n    \t\t\t\t<\/div>\r\n    \t\t\t<\/div><!-- \/ht-toggle-content -->\r\n    \t\t<\/div>\r\n    \t\t\n<h2>Basic Mac shell scripting terms to familiarize<\/h2>\n<p><center><a href=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/Creating-and-editing-Mac-shell-scripts.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" class=\"\" src=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/Creating-and-editing-Mac-shell-scripts.png\" alt=\"Creating and editing Mac shell scripts\" width=\"682\" height=\"425\" \/><\/a><\/center><center><em>Creating and editing Mac shell scripts<\/em><\/center>&nbsp;<\/p>\n<p>Alright, so now that you\u2019ve decided on the right shell, it is time to begin scripting. But wait? How will a sailor be ready to sail his ship through dangerous oceans, without even knowing what \u2018port\u2019, \u2018starboard\u2019, \u2018stern\u2019, or \u2018bow\u2019 means?<\/p>\n<p>That\u2019s right, much like a sailor should be familiar with all the sailing terms for communication, every programmer should know the basic terms and expressions that their fellow programmers may use when coding and documenting their scripts. Let\u2019s take a look at a few of the common ones here.<\/p>\n<h4>What are variables?<\/h4>\n<p>Variables are the term given to a block of memory to which we may assign values, read, and alter their contents. Just about every programming language in existence has the concept of variables, and shells are no exception.<\/p>\n    \t\t<div class=\"hts-toggle  \"  >\r\n    \t\t\t<div class=\"hts-toggle__title\">Syntax and examples for 'variables'<\/div>\r\n    \t\t\t<div class=\"hts-toggle__content\">\r\n    \t\t\t\t<div class=\"hts-toggle__contentwrap\">\r\n    \t\t\t\t\t<p>The syntax for a variable in shell would be as follows.<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Syntax for a variable in shell programming\">VAR=val<\/pre>\n<\/div>\n<p>Where <strong>VAR<\/strong> is the variable and <strong>val<\/strong> is the value given to the variable.<\/p>\n<p>Unlike other programming languages, the shell does not care about the classification of variables. Instead, they store strings, integers, and real numbers the same way. However, it is important to note that a variable can only hold one value. Hence, a string separated by spaces must be quoted. For example, in the following line,<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"String variable example without double quotes\">VAR=Hello World<\/pre>\n<\/div>\n<p>The variable <strong>VAR<\/strong> will store the string <strong>Hello<\/strong>, but try to execute the command <strong>World<\/strong>. Hence, the right assignment for such a variable would be as follows.<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"String variable example with double quotes\">VAR=\"Hello World\"<\/pre>\n<\/div>\n<p>\n    \t\t\t\t<\/div>\r\n    \t\t\t<\/div><!-- \/ht-toggle-content -->\r\n    \t\t<\/div>\r\n    \t\t\n<h4>What are arguments?<\/h4>\n<p>A command-line argument is a value that we may pass to our Bash script when it runs. They let a user dynamically change the actions a script takes or the results it produces.<\/p>\n<p>To pass an argument to your Bash script, simply type in the arguments after the name of the script, during the script execution <em>(The next section speaks more about script execution)<\/em>.<\/p>\n    \t\t<div class=\"hts-toggle  \"  >\r\n    \t\t\t<div class=\"hts-toggle__title\">Syntax and examples for 'arguments'<\/div>\r\n    \t\t\t<div class=\"hts-toggle__content\">\r\n    \t\t\t\t<div class=\"hts-toggle__contentwrap\">\r\n    \t\t\t\t\t<p>The syntax would be,<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Syntax for passing arguments to a script\">shellextension .\/scriptname.extenstion argument1 argument2<\/pre>\n<\/div>\n<p>For example,<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Command example for passing arguments to a script\">sh .\/myscript.sh good luck<\/pre>\n<\/div>\n<p>The bash shell supports arguments from $1 to $9. Here, the first argument is stored in $1, the second in $2, and so on.<\/p>\n<p>Let\u2019s see how this works using an example script:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Example script with passable arguments\">#!bin\/bash\r\necho \"Checking parameters: $1 $2\"<\/pre>\n<\/div>\n<p>Let&#8217;s see what the above script looks like, when no arguments are passed.<\/p>\n<p><center><a href=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/Executing-a-shell-script-without-passing-arguments.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" class=\"\" src=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/Executing-a-shell-script-without-passing-arguments.png\" alt=\"Executing a shell script without passing arguments\" width=\"682\" height=\"425\" \/><\/a><\/center><center><em>Executing a shell script without passing arguments<\/em><\/center>&nbsp;<\/p>\n<p>As noticed, if we run our script and no arguments are passed, we will see no output for our pre-defined variables. Now, let&#8217;s see what this script looks like when passing arguments.<\/p>\n<p><center><a href=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/Executing-a-shell-script-while-passing-arguments.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" class=\"\" src=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/Executing-a-shell-script-while-passing-arguments.png\" alt=\"Executing a shell script while passing arguments\" width=\"682\" height=\"425\" \/><\/a><\/center><center><em>Executing a shell script while passing arguments<\/em><\/center>&nbsp;<\/p>\n<p>Here, our script detects these arguments and provides the values to our pre-defined variables.<\/p>\n    \t\t\t\t<\/div>\r\n    \t\t\t<\/div><!-- \/ht-toggle-content -->\r\n    \t\t<\/div>\r\n    \t\t\n<h4>What are conditionals?<\/h4>\n<p>The conditional statement is used in programming languages to perform decision-making tasks. It enables you to change the flow of control in a program. There are a total of 5 conditional statements that may be used in shell programming.<\/p>\n    \t\t<div class=\"hts-toggle  \"  >\r\n    \t\t\t<div class=\"hts-toggle__title\">if conditional<\/div>\r\n    \t\t\t<div class=\"hts-toggle__content\">\r\n    \t\t\t\t<div class=\"hts-toggle__contentwrap\">\r\n    \t\t\t\t\t<p>The syntax for the <strong>if conditional<\/strong> is as follows:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Syntax for the 'if' conditional\">if [ logic ]\u00a0\r\nthen\u00a0\r\n\u00a0 \u00a0statement\u00a0\r\nfi<\/pre>\n<\/div>\n<p>\n    \t\t\t\t<\/div>\r\n    \t\t\t<\/div><!-- \/ht-toggle-content -->\r\n    \t\t<\/div>\r\n    \t\t\n    \t\t<div class=\"hts-toggle  \"  >\r\n    \t\t\t<div class=\"hts-toggle__title\">if-else conditional<\/div>\r\n    \t\t\t<div class=\"hts-toggle__content\">\r\n    \t\t\t\t<div class=\"hts-toggle__contentwrap\">\r\n    \t\t\t\t\t<p>The syntax for the <strong>if-else conditional<\/strong> is as follows:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Syntax for the 'if-else' conditional\">if [ logic ]\u00a0\r\nthen\u00a0\r\n\u00a0 \u00a0statement1\u00a0\r\nelse\u00a0\r\n\u00a0 \u00a0statement2\u00a0\r\nfi<\/pre>\n<\/div>\n<p>\n    \t\t\t\t<\/div>\r\n    \t\t\t<\/div><!-- \/ht-toggle-content -->\r\n    \t\t<\/div>\r\n    \t\t\n    \t\t<div class=\"hts-toggle  \"  >\r\n    \t\t\t<div class=\"hts-toggle__title\">if-elif-else conditional (Else If ladder) <\/div>\r\n    \t\t\t<div class=\"hts-toggle__content\">\r\n    \t\t\t\t<div class=\"hts-toggle__contentwrap\">\r\n    \t\t\t\t\t<p>The syntax for the <strong>else-if ladder conditional<\/strong> is as follows:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Syntax for the 'else-if ladder' conditional\">if [ logic1 ]\u00a0\r\nthen\u00a0\r\n\u00a0 \u00a0statement1\u00a0\r\nelif [ logic2 ]\u00a0\r\nthen\u00a0\r\n\u00a0 \u00a0statement2\u00a0\r\nelse\u00a0\r\n\u00a0 \u00a0statement3\u00a0\r\nfi<\/pre>\n<\/div>\n<p>\n    \t\t\t\t<\/div>\r\n    \t\t\t<\/div><!-- \/ht-toggle-content -->\r\n    \t\t<\/div>\r\n    \t\t\n    \t\t<div class=\"hts-toggle  \"  >\r\n    \t\t\t<div class=\"hts-toggle__title\">if-then-else-if-then conditional (Nested if) <\/div>\r\n    \t\t\t<div class=\"hts-toggle__content\">\r\n    \t\t\t\t<div class=\"hts-toggle__contentwrap\">\r\n    \t\t\t\t\t<p>The syntax for the <strong>nested-if conditional<\/strong> is as follows:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Syntax for the 'nested-if' conditional\">if [ logic1 ]\u00a0\r\nthen\u00a0\r\n\u00a0 \u00a0statement1\u00a0\r\nelse\u00a0\r\n\u00a0 \u00a0if [ logic2 ]\u00a0\r\n\u00a0 \u00a0then\u00a0\r\n\u00a0 \u00a0 \u00a0\u00a0statement2\u00a0\r\n\u00a0 \u00a0fi\u00a0\r\nfi<\/pre>\n<\/div>\n<p>\n    \t\t\t\t<\/div>\r\n    \t\t\t<\/div><!-- \/ht-toggle-content -->\r\n    \t\t<\/div>\r\n    \t\t\n    \t\t<div class=\"hts-toggle  \"  >\r\n    \t\t\t<div class=\"hts-toggle__title\">switch conditional<\/div>\r\n    \t\t\t<div class=\"hts-toggle__content\">\r\n    \t\t\t\t<div class=\"hts-toggle__contentwrap\">\r\n    \t\t\t\t\t<p>The syntax for the <strong>switch conditional<\/strong> is as follows:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Syntax for the 'switch' conditional\">case in\u00a0\r\n\u00a0 \u00a0case2) Statement 1;;\u00a0\r\n\u00a0 \u00a0case 2) Statement 2;;\u00a0\r\nesac<\/pre>\n<\/div>\n<p>\n    \t\t\t\t<\/div>\r\n    \t\t\t<\/div><!-- \/ht-toggle-content -->\r\n    \t\t<\/div>\r\n    \t\t\n<h4>What are wildcards?<\/h4>\n<p>A wildcard is a character that may be used as a substitute for a class of characters in a search, thereby significantly increasing the flexibility and efficiency of searches.<\/p>\n<p>There are three main wildcards in bash:<\/p>\n    \t\t<div class=\"hts-toggle  \"  >\r\n    \t\t\t<div class=\"hts-toggle__title\">Asterisk (*)<\/div>\r\n    \t\t\t<div class=\"hts-toggle__content\">\r\n    \t\t\t\t<div class=\"hts-toggle__contentwrap\">\r\n    \t\t\t\t\t<p><span class=\"TextRun BCX0 SCXW88394505\" lang=\"EN-GB\" xml:lang=\"EN-GB\" data-contrast=\"none\"><span class=\"NormalTextRun BCX0 SCXW88394505\">This wildcard is used to match and provide the result of one or more occurrences of any character.<\/span><\/span><\/p>\n<p>For example,<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Sample use of the asterix (*) wildcard\">ls a*s<\/pre>\n<\/div>\n<p><span class=\"TextRun SCXW171680196 BCX0\" lang=\"EN-GB\" xml:lang=\"EN-GB\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW171680196 BCX0\">provides the list of all files and folders starting with <strong>a<\/strong> and ending with <strong>s<\/strong>.<\/span><\/span><span class=\"EOP SCXW171680196 BCX0\" data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n    \t\t\t\t<\/div>\r\n    \t\t\t<\/div><!-- \/ht-toggle-content -->\r\n    \t\t<\/div>\r\n    \t\t\n    \t\t<div class=\"hts-toggle  \"  >\r\n    \t\t\t<div class=\"hts-toggle__title\">Question mark (?)<\/div>\r\n    \t\t\t<div class=\"hts-toggle__content\">\r\n    \t\t\t\t<div class=\"hts-toggle__contentwrap\">\r\n    \t\t\t\t\t<p><span class=\"TextRun BCX0 SCXW243265823\" lang=\"EN-GB\" xml:lang=\"EN-GB\" data-contrast=\"none\"><span class=\"NormalTextRun BCX0 SCXW243265823\">This wildcard is used to match and provide the result of a single occurrence of any character.<\/span><\/span><\/p>\n<p>For example:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Sample use of the question mark (?) wildcard\">ls a??s<\/pre>\n<\/div>\n<p><span class=\"TextRun SCXW83515024 BCX0\" lang=\"EN-GB\" xml:lang=\"EN-GB\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW83515024 BCX0\">provides the list of all files and folders starting with <strong>a<\/strong> and ending with <strong>s<\/strong>, with only two characters in between.<\/span><\/span><span class=\"EOP SCXW83515024 BCX0\" data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n    \t\t\t\t<\/div>\r\n    \t\t\t<\/div><!-- \/ht-toggle-content -->\r\n    \t\t<\/div>\r\n    \t\t\n    \t\t<div class=\"hts-toggle  \"  >\r\n    \t\t\t<div class=\"hts-toggle__title\">&#8221;Bracketed<\/div>\r\n    \t\t\t<div class=\"hts-toggle__content\">\r\n    \t\t\t\t<div class=\"hts-toggle__contentwrap\">\r\n    \t\t\t\t\t<p>)&#8221; id=&#8221;&#8221; class=&#8221;&#8221; style=&#8221;&#8221; ]This wildcard is used to match and provide the result of any occurrence of the characters enclosed in the square brackets.<\/p>\n<p>For example:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Sample use of the bracketed characters ([ ]) wildcard\">ls a[pn]s<\/pre>\n<\/div>\n<p><span class=\"TextRun SCXW20902921 BCX0\" lang=\"EN-GB\" xml:lang=\"EN-GB\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW20902921 BCX0\">provides the list of all files and folders starting with <strong>a<\/strong> and ending with <strong>s<\/strong>, and having either the characters <strong>p<\/strong> or <strong>n<\/strong> in between.<\/span><\/span><span class=\"EOP SCXW20902921 BCX0\" data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n    \t\t\t\t<\/div>\r\n    \t\t\t<\/div><!-- \/ht-toggle-content -->\r\n    \t\t<\/div>\r\n    \t\t\n<h4>What do you mean by piping?<\/h4>\n<p>A pipe is a form of redirection used in shell programming, to send the output of one command or process to another command\/process. This is done by using the pipe character \u2018<strong>|<\/strong>\u2019.<\/p>\n<p>In a nutshell, pipe is used to combine two or more commands, and take the output of the first command as the input of the second command.<\/p>\n    \t\t<div class=\"hts-toggle  \"  >\r\n    \t\t\t<div class=\"hts-toggle__title\">Syntax and examples for 'piping'<\/div>\r\n    \t\t\t<div class=\"hts-toggle__content\">\r\n    \t\t\t\t<div class=\"hts-toggle__contentwrap\">\r\n    \t\t\t\t\t<p>The syntax is as follows.<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Syntax for the 'pipe' command\">command_1 | command_2 | command_3 | .... | command_N<\/pre>\n<\/div>\n<p>For example, let&#8217;s consider the following command.<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Sample 'pipe' command\">ls | more<\/pre>\n<\/div>\n<p>Where, the more command displays text files, one screen at a time.<\/p>\n<p>Here, the <strong>more<\/strong> command takes the output of <strong>ls<\/strong> as its input. Hence, the final effect of the command is that the output of <strong>ls<\/strong> is displayed one screen at a time.<\/p>\n    \t\t\t\t<\/div>\r\n    \t\t\t<\/div><!-- \/ht-toggle-content -->\r\n    \t\t<\/div>\r\n    \t\t\n<h4>What is the &#8216;man&#8217; command?<\/h4>\n<p>The <strong>man<\/strong> command in bash displays the user manual of any command that you can run on the terminal. It provides detailed information on the command, including sections such as NAME, SYNOPSIS, DESCRIPTION, OPTIONS, EXIT STATUS, RETURN VALUES, ERRORS, FILES, VERSIONS, EXAMPLES, AUTHORS and SEE ALSO.<\/p>\n    \t\t<div class=\"hts-toggle  \"  >\r\n    \t\t\t<div class=\"hts-toggle__title\">Syntax and examples for the 'man' command<\/div>\r\n    \t\t\t<div class=\"hts-toggle__content\">\r\n    \t\t\t\t<div class=\"hts-toggle__contentwrap\">\r\n    \t\t\t\t\t<p>The syntax for the man command is as follows:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Syntax for the 'man' command\">man [option] [command name]<\/pre>\n<\/div>\n<p>Here, if we do not specify an option parameter, the terminal displays the entire manual for the searched command. Some arguments you can specify for the option parameter include,<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Syntax for the 'man' command with a 'section number' parameter\">man [section_number] [command name]<\/pre>\n<\/div>\n<p>You can use this command to display only a specific section of a manual. For example,<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Sample 'man' command with 'section number' parameter\">man 2 intro<\/pre>\n<\/div>\n<p>Similarly,<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true\" title=\"Syntax for the 'man' command with 'f' parameter\">man -f [COMMAND NAME]<\/pre>\n<\/div>\n<p>shows all the sections in which the given command is present. For example,<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true\" title=\"Sample 'man' command with 'f' parameter\">man -f echo<\/pre>\n<\/div>\n<p>\n    \t\t\t\t<\/div>\r\n    \t\t\t<\/div><!-- \/ht-toggle-content -->\r\n    \t\t<\/div>\r\n    \t\t\n<h2>How do I create a Mac shell script?<\/h2>\n<p><center><a href=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/IT-editing-shell-scripts-on-a-Mac.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" class=\"\" src=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/IT-editing-shell-scripts-on-a-Mac.png\" alt=\"IT editing shell scripts on a Mac\" width=\"682\" height=\"425\" \/><\/a><\/center><center><em>IT editing shell scripts on a Mac<\/em><\/center>&nbsp;<\/p>\n<p>There are many ways to create a shell script on a Mac. However, regardless of the method you may use to create your shell scripts, the fundamental instructions remain common for all these cases. Let&#8217;s take a look at the instructions.<\/p>\n<ul>\n<li>Begin editing your script by typing in <strong>#!<\/strong> followed by the binary path into the first line (the binary path will differ depending on the shell you\u2019re using).<\/li>\n<\/ul>\n    \t\t<div class=\"hts-messages hts-messages--alert  hts-messages--withtitle  \"   >\r\n    \t\t\t<span class=\"hts-messages__title\"><\/p>\n<h4>Some common shells and their binary paths<\/h4>\n<p><\/span>    \t\t\t    \t\t\t\t<p>\r\n    \t\t\t\t\t<\/p>\n<ul>\n<li><em><strong>Perl:<\/strong> \/usr\/bin\/perl<\/em><\/li>\n<li><em><strong>Bash:<\/strong> \/bin\/bash<\/em><\/li>\n<li><em><strong>Shell:<\/strong> \/bin\/sh<\/em><\/li>\n<li><em><strong>C Shell:<\/strong> \/bin\/csh<\/em><\/li>\n<li><em><strong>Zsh:<\/strong> \/bin\/zsh<\/em><\/li>\n<li><em><strong>Korn Shell:<\/strong> \/bin\/ksh<\/em><\/li>\n<li><em><strong>Python:<\/strong> \/usr\/bin\/python<\/em><\/li>\n<li><em><strong>Hypertext Preprocessor:<\/strong> \/usr\/bin\/php<\/em><\/li>\n<li><em><strong>Ruby:<\/strong> \/usr\/bin\/ruby<\/em><\/li>\n<\/ul>\n<p>    \t\t\t\t<\/p>\r\n    \t\t\t    \t\t\t\r\n    \t\t<\/div><!-- \/.ht-shortcodes-messages -->\r\n    \t\t\n<ul>\n<li>Add all the necessary commands into your script file and save the file as a plain text (.txt) or as an executable.<\/li>\n<\/ul>\n<p>Alright, now, let\u2019s take a look at some of the methods you may adopt to create a shell script.<\/p>\n    \t\t<div class=\"hts-toggle  \"  >\r\n    \t\t\t<div class=\"hts-toggle__title\">Using TextEdit<\/div>\r\n    \t\t\t<div class=\"hts-toggle__content\">\r\n    \t\t\t\t<div class=\"hts-toggle__contentwrap\">\r\n    \t\t\t\t\t<p>Creating scripts via TextEdit is the most basic method you can use to create and run shell scripts on a Mac. The primary benefit of this method is that it does not require any third-party tools or applications for performing this process. Let\u2019s take a look at the steps.<\/p>\n<h4>To create a text file using TextEdit<\/h4>\n<ul>\n<li>Open <strong>TextEdit<\/strong> from <em><strong>Applications<\/strong><\/em> tab<\/li>\n<li>Type in <strong>#!<\/strong> followed by the binary path into the first line (the binary path will differ depending on the shell you\u2019re using)<\/li>\n<\/ul>\n<p style=\"padding-left: 40px;\">Now, add the necessary commands into the TextEditor.<\/p>\n<p><center><a href=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/Creating-a-shell-script-using-the-TextEdit-app.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" class=\"\" src=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/Creating-a-shell-script-using-the-TextEdit-app.png\" alt=\"Creating a shell script using the TextEdit app\" width=\"682\" height=\"425\" \/><\/a><\/center><center><em>Creating a shell script using the TextEdit app<\/em><\/center>&nbsp;<\/p>\n<ul>\n<li>Next, you must convert the text file from <em><strong>Rich Text (.rtf)<\/strong><\/em> to <em><strong>Plain Text (.txt)<\/strong><\/em>. To do so, expand the <strong>Format<\/strong> tab on the top status bar, and click on <strong>Make Plain Text<\/strong>.<\/li>\n<li>Click <strong>Ok<\/strong>\u00a0and save the text file.<\/li>\n<\/ul>\n<p><center><a href=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/Converting-a-file-from-.rtf-to-.txt-in-TextEdit.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" class=\"\" src=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/Converting-a-file-from-.rtf-to-.txt-in-TextEdit.png\" alt=\"Converting a file from .rtf to .txt in TextEdit\" width=\"682\" height=\"425\" \/><\/a><\/center><center><em>Converting a file from .rtf to .txt in TextEdit<\/em><\/center>&nbsp;<\/p>\n<p style=\"padding-left: 40px;\"><em>Some of us may be wondering, what if the file has already been created in <strong>Rich Text format<\/strong>, and you do not have the means to change it? No worries. Open <strong>Terminal<\/strong> and navigate to the file location using <strong>cd<\/strong> commands. Then, run the following command: <\/em><\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Syntax to convert the extension of a file\">textutil -convert filetype filename<\/pre>\n<\/div>\n<p style=\"padding-left: 40px;\"><em>For example, <\/em><\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Sample command to convert file extension from .rtf to .txt\">textutil \u2013convert txt TestScript.rtf<\/pre>\n<\/div>\n<p>Your file has been converted to <strong>Plain Text format<\/strong>.<\/p>\n<p><center><a href=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/Converting-a-file-from-.rtf-to-.txt-using-Terminal-commands.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" class=\"\" src=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/Converting-a-file-from-.rtf-to-.txt-using-Terminal-commands.png\" alt=\"Converting a file from .rtf to .txt using Terminal commands\" width=\"682\" height=\"425\" \/><\/a><\/center><center><em>Converting a file from .rtf to .txt using Terminal commands<\/em><\/center><\/p>\n    \t\t\t\t<\/div>\r\n    \t\t\t<\/div><!-- \/ht-toggle-content -->\r\n    \t\t<\/div>\r\n    \t\t\n    \t\t<div class=\"hts-toggle  \"  >\r\n    \t\t\t<div class=\"hts-toggle__title\">Using Xcode<\/div>\r\n    \t\t\t<div class=\"hts-toggle__content\">\r\n    \t\t\t\t<div class=\"hts-toggle__contentwrap\">\r\n    \t\t\t\t\t<p>You can create shell script files using <strong><a href=\"https:\/\/developer.apple.com\/xcode\/\" target=\"_blank\" rel=\"noopener noreferrer nofollow\">Xcode<\/a><\/strong>, which you can then save as an executable and run from the terminal. Lat\u2019s take a look at how.<\/p>\n<ul>\n<li>Install and open <strong>Xcode<\/strong> from the <strong><a href=\"https:\/\/apps.apple.com\/in\/app\/xcode\/id497799835?mt=12\" target=\"_blank\" rel=\"noopener noreferrer nofollow\">App Store<\/a><\/strong>. Once opened, navigate to the top left status bar, where you can then expand the <strong>File<\/strong>\u00a0dropdown.<\/li>\n<li>Hover over <strong>New<\/strong>, and select the <strong>File<\/strong> option that comes up.<\/li>\n<li>Next, scroll down to the <strong>Others<\/strong> section on the tab that pops up, and select the option marked <strong>Shell script<\/strong>. Click <strong>Next<\/strong>.<\/li>\n<li>Expand the <strong>Create<\/strong> dialog box that opens up, by clicking on the dropdown button, and decide on where you want to save your shell script file.<\/li>\n<li>Once this is done, the script editor opens up.<\/li>\n<li>You may now create and save your shell script.<\/li>\n<\/ul>\n<p><center><a href=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/Creating-a-shell-script-using-Xcode.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" class=\"\" src=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/Creating-a-shell-script-using-Xcode.png\" alt=\"Creating a shell script using Xcode\" width=\"682\" height=\"425\" \/><\/a><\/center><center><em>Creating a shell script using Xcode<\/em><\/center><\/p>\n    \t\t\t\t<\/div>\r\n    \t\t\t<\/div><!-- \/ht-toggle-content -->\r\n    \t\t<\/div>\r\n    \t\t\n    \t\t<div class=\"hts-toggle  \"  >\r\n    \t\t\t<div class=\"hts-toggle__title\">Using pico or nano commands (ideal during remote SSH sessions) <\/div>\r\n    \t\t\t<div class=\"hts-toggle__content\">\r\n    \t\t\t\t<div class=\"hts-toggle__contentwrap\">\r\n    \t\t\t\t\t<p>If you&#8217;re using SSH to connect to a computer remotely, you&#8217;ll need a text editor that can be launched from the command line.<\/p>\n<p>Pico and nano are two such command-line text editors that are incredibly simple to use.<\/p>\n<h4>To create a text file using nano or pico commands<\/h4>\n<p>Open <strong>Terminal<\/strong> and use <strong>cd<\/strong> commands to navigate to the directory where you want to create or edit the text file.<\/p>\n<p>Enter the following command:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Using nano command to convert the Terminal to a text editor\">nano filename.txt<\/pre>\n<\/div>\n<p>OR<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Using pico command to convert the Terminal to a text editor\">pico filename.txt<\/pre>\n<\/div>\n<p>The terminal is now converted into a text editor. You can now edit the text file. Use arrow keys to navigate.<\/p>\n<p><center><a href=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/Creating-a-.txt-file-using-the-nano-command.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" class=\"\" src=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/Creating-a-.txt-file-using-the-nano-command.png\" alt=\"Creating a .txt file using the nano command\" width=\"682\" height=\"425\" \/><\/a><\/center><center><em>Creating a .txt file using the nano command<\/em><\/center>&nbsp;<\/p>\n<p>When you are finished with editing, press <strong>Control + O<\/strong> to save the file and if required, edit the filename. Press <strong>Enter<\/strong> once you&#8217;re done.<\/p>\n<p>You can now exit the editor by pressing <strong>Control + X<\/strong>.<\/p>\n<p>To view the complete documentation for the nano command, hold down <strong>Control + G<\/strong> when working on the text editor in the terminal.<\/p>\n<p><center><a href=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/Editing-a-file-on-Terminal-using-the-nano-command.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" class=\"\" src=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/Editing-a-file-on-Terminal-using-the-nano-command.png\" alt=\"Editing a file on Terminal using the nano command\" width=\"682\" height=\"425\" \/><\/a><\/center><center><em>Editing a file on Terminal using the nano command<\/em><\/center><\/p>\n    \t\t\t\t<\/div>\r\n    \t\t\t<\/div><!-- \/ht-toggle-content -->\r\n    \t\t<\/div>\r\n    \t\t\n    \t\t<div class=\"hts-toggle  \"  >\r\n    \t\t\t<div class=\"hts-toggle__title\">Using Third-party tools <\/div>\r\n    \t\t\t<div class=\"hts-toggle__content\">\r\n    \t\t\t\t<div class=\"hts-toggle__contentwrap\">\r\n    \t\t\t\t\t<p>You can also use third-party tools such as <strong><a href=\"https:\/\/www.sublimetext.com\/\" target=\"_blank\" rel=\"noopener noreferrer nofollow\">Sublime<\/a><\/strong> or <strong><a href=\"https:\/\/atom.io\/\" target=\"_blank\" rel=\"noopener noreferrer nofollow\">Atom<\/a><\/strong> to create executable shell script files. In such cases, use the tool to save the script file as an executable. Then, open <strong>Terminal<\/strong> and navigate to the file using <strong>cd<\/strong> commands. You can then directly run the file using the following command:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Syntax to execute a shell file\">(shell) .\/(filename)<\/pre>\n<\/div>\n<p>For example,<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true\" title=\"Sample command to execute a shell file\">bash .\/TestScript.txt<\/pre>\n<\/div>\n<p>\n    \t\t\t\t<\/div>\r\n    \t\t\t<\/div><!-- \/ht-toggle-content -->\r\n    \t\t<\/div>\r\n    \t\t\n<h2>How do I execute a Mac shell script?<\/h2>\n<p>To run a Mac shell script, you must first convert the .txt file into an executabe. Then, you can execute the file as a shell script. In case your file is already saved as a shell scipt file (usually occurs when creating files via third-party tools), you can skip executing the first command that&#8217;s mentioned below.<br \/>\n    \t\t<div class=\"hts-toggle  \"  >\r\n    \t\t\t<div class=\"hts-toggle__title\">Steps to execute a shell script<\/div>\r\n    \t\t\t<div class=\"hts-toggle__content\">\r\n    \t\t\t\t<div class=\"hts-toggle__contentwrap\">\r\n    \t\t\t\t\t<\/p>\n<ul>\n<li>Open Terminal and navigate to the saved text file using <strong>cd<\/strong> commands.<\/li>\n<li>Now, you must convert the text file into an executable. Use the following command:<\/li>\n<\/ul>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Syntax to convert a file into a shell executable\">chmod 700 (filename)<\/pre>\n<\/div>\n<p style=\"padding-left: 40px;\">For example,<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Sample command to convert a .txt file into an executable\">chmod 700 TestScript.txt<\/pre>\n<\/div>\n<p style=\"padding-left: 40px;\"><em><strong>This command may vary depending on the shell you\u2019re using.<\/strong><\/em><\/p>\n<p style=\"padding-left: 40px;\"><em>You will notice no change in the Terminal or on the actual file when you enter this command. However, don\u2019t be thrown off by this, as your file has simply been converted to an executable.<\/em><\/p>\n<p style=\"padding-left: 40px;\">Next, to execute your file, type in the following command:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Syntax to execute a shell file\">(shell) .\/(filename)<\/pre>\n<\/div>\n<p style=\"padding-left: 40px;\">For example,<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true\" title=\"Sample command to execute a shell file\">bash .\/TestScript.txt<\/pre>\n<\/div>\n<p>You have successfully <strong>executed your script<\/strong>.<\/p>\n<p><center><a href=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/Executing-a-shell-script.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" class=\"\" src=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/Executing-a-shell-script.png\" alt=\"Executing a shell script\" width=\"682\" height=\"425\" \/><\/a><\/center><center><em>Executing a shell script<\/em><\/center>&nbsp;<\/p>\n<p>\n    \t\t\t\t<\/div>\r\n    \t\t\t<\/div><!-- \/ht-toggle-content -->\r\n    \t\t<\/div>\r\n    \t\t<\/p>\n<h2>Simplify script deployments using UEM<\/h2>\n<p>When employing a <a href=\"https:\/\/www.hexnode.com\/blogs\/what-is-unified-endpoint-management-uem\/?utm_source=hexnode_blog_mac_shell_scripting&amp;utm_medium=referral&amp;utm_campaign=internal_link\" target=\"_blank\" rel=\"noopener\">Unified Endpoint Management<\/a> solution, <a href=\"https:\/\/www.hexnode.com\/mobile-device-management\/help\/how-to-run-scripts-on-mac-using-hexnode-mdm\/?utm_source=hexnode_blog_mac_shell_scripting&amp;utm_medium=referral&amp;utm_campaign=internal_link\" target=\"_blank\" rel=\"noopener\">deploying shell scripts<\/a> to your managed macOS devices turns out to be a pretty straightforward process.<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"qEx49WSpG9\"><p><a href=\"https:\/\/www.hexnode.com\/blogs\/executing-custom-mac-scripts-via-mdm\/\">A quick guide to executing custom Mac scripts via MDM<\/a><\/p><\/blockquote>\n<p><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;A quick guide to executing custom Mac scripts via MDM&#8221; &#8212; Hexnode Blogs\" src=\"https:\/\/www.hexnode.com\/blogs\/executing-custom-mac-scripts-via-mdm\/embed\/#?secret=MoOOvlwuX6#?secret=qEx49WSpG9\" data-secret=\"qEx49WSpG9\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<p>IT admins may often find themselves in situations where they may need to deploy different sets of scripts to specific categories of devices. In such cases, employing a UEM solution can help you create<a href=\"https:\/\/www.hexnode.com\/mobile-device-management\/help\/dynamic-device-groups\/?utm_source=hexnode_blog_mac_shell_scripting&amp;utm_medium=referral&amp;utm_campaign=internal_link\" target=\"_blank\" rel=\"noopener\"> dynamic device and user groups<\/a>, which you can then use to push and run scripts. Moreover, you can keep track of the script\u2019s response and execution status remotely, straight from the UEM console.<\/p>\n<section id='resource-single'>\n                    <div class='resource-box'>\n                        <div class='resource-box__image-section'>\n                            <div class='resource-box__image-wrap'>\n                                <img decoding=\"async\" src=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/mac-device-management-whitepaper.jpeg?format=webp\" class=\"resource-box__image\" alt=\"mac device management whitepaper\" loading=\"lazy\" srcset=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/mac-device-management-whitepaper.jpeg?format=webp 960w, https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/mac-device-management-whitepaper-300x225.jpeg?format=webp 300w, https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/mac-device-management-whitepaper-768x576.jpeg?format=webp 768w, https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/mac-device-management-whitepaper-133x100.jpeg?format=webp 133w\" sizes=\"auto, (max-width: 960px) 100vw, 960px\" title=\"mac device management whitepaper\" \/>\n                            <\/div>\n                        <\/div>\n                        <div class='resource-box__content-section'>\n                            <h5 class='resource-box__content-subheading'>\n                            WHITEPAPER\n                            <\/h5>\n                            <h4 class='resource-box__content-heading'>\n                            A complete guide to Mac device management\n                            <\/h4>\n                            <p class='resource-box__contents'>\n                            Macbooks have become the go-to devices for enterprises due to their cost-effective price and efficient OS. Read more about Mac device management from our whitepaper.\n                            <\/p>\n                            <a class='resource-box__content-link hn-cta__blogs--resource-box' href='https:\/\/www.hexnode.com\/resources\/register\/?resource=MTUyNw==&datacount=1&utm_source=hexnode_blog_mac_shell_scripting&utm_medium=referral&utm_campaign=resource_box'>\n                            DOWNLOAD PDF\n                            <svg xmlns='http:\/\/www.w3.org\/2000\/svg' width='20' height='20' viewBox='0 0 20 20'>\n                            <g id='arrow' transform='translate(-309 -191)' opacity='0'>\n                                <rect id='base' width='20' height='20' transform='translate(309 191)' fill='none'\/>\n                                <path id='arrow-2' data-name='arrow' d='M13.093.5,6.8,6.8.5.5' transform='translate(315 207.594) rotate(-90)' fill='none' stroke='#0549d1' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.2'\/>\n                            <\/g>\n                            <\/svg>\n\n                            <\/a>\n                        <\/div>\n                    <\/div>\n                <\/section>\n<h2>Some frequently used shell commands<\/h2>\n<p><center><a href=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2021\/08\/Anywhere-operations-model-simplifies-remote-work.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img loading=\"lazy\" decoding=\"async\" class=\"\" src=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2021\/08\/Anywhere-operations-model-simplifies-remote-work.png\" alt=\"Employee working on a Mac\" width=\"682\" height=\"425\" \/><\/a><\/center><center><em>Employee working on a Mac<\/em><\/center>&nbsp;<\/p>\n<p>With so many Mac Terminal commands available out there, it&#8217;s often difficult to identify and correctly use them all. We&#8217;re here to help you out with a list of some commonly used Mac shell commands.<\/p>\n    \t\t<div class=\"hts-toggle  \"  >\r\n    \t\t\t<div class=\"hts-toggle__title\">The concatenate (cat) command<\/div>\r\n    \t\t\t<div class=\"hts-toggle__content\">\r\n    \t\t\t\t<div class=\"hts-toggle__contentwrap\">\r\n    \t\t\t\t\t<p>The cat command is one of the most frequently used commands in the macOS operating system. It has four primary functions related to it &#8211; <strong>creating<\/strong>, <strong>displaying<\/strong>, <strong>editing<\/strong>, and <strong>combining<\/strong> text files.<\/p>\n<p>To view a file, use the following command:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Shell command to view a file in terminal\">cat filename.extension<\/pre>\n<\/div>\n<p>To replace text in a file, use the following command:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Shell command to replace text in a file\">cat &gt; filename.extension<\/pre>\n<\/div>\n<p>If the file does not exist, a new file is created. You can press <strong>ctrl + d<\/strong> to stop editing.<\/p>\n<p>To append the content in a text file, use the following command:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Shell command to append text in a file\">cat &gt;&gt; filename.extension<\/pre>\n<\/div>\n<p>You can press <strong>ctrl + d<\/strong> to stop editing.<\/p>\n<p>To combine two files and save the result to a third file, use the following command:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Shell command to combine the content in two files and save it in a third file\">cat file1.extension file2.extension &gt; file3.extension<\/pre>\n<\/div>\n<p>\n    \t\t\t\t<\/div>\r\n    \t\t\t<\/div><!-- \/ht-toggle-content -->\r\n    \t\t<\/div>\r\n    \t\t\n    \t\t<div class=\"hts-toggle  \"  >\r\n    \t\t\t<div class=\"hts-toggle__title\">The change directory (cd) command <\/div>\r\n    \t\t\t<div class=\"hts-toggle__content\">\r\n    \t\t\t\t<div class=\"hts-toggle__contentwrap\">\r\n    \t\t\t\t\t<p>The change directory (<strong>cd<\/strong>) command is used to change the <strong>current working directory<\/strong> the terminal is pointing at. It is one of the most basic and frequently used commands you will encounter when working on the Linux terminal.<\/p>\n<p>To change the current working directory to the Home folder, give the following command:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Command to change current working directory to the home folder\">cd<\/pre>\n<\/div>\n<p>To go back to the directory you were in before you issued the cd command, type in the following command:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Command to go back to previous directory\">cd -<\/pre>\n<\/div>\n<div class=\"copy-code-download\">\n<p>To go to the directory above the one you\u2019re currently in, type in the following command:<\/p>\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Command to go back one directory\">cd..<\/pre>\n<\/div>\n<p>\n    \t\t\t\t<\/div>\r\n    \t\t\t<\/div><!-- \/ht-toggle-content -->\r\n    \t\t<\/div>\r\n    \t\t\n    \t\t<div class=\"hts-toggle  \"  >\r\n    \t\t\t<div class=\"hts-toggle__title\">The copy (cp) and move (mv) command <\/div>\r\n    \t\t\t<div class=\"hts-toggle__content\">\r\n    \t\t\t\t<div class=\"hts-toggle__contentwrap\">\r\n    \t\t\t\t\t<p>Using the copy (<strong>cp<\/strong>) and move (<strong>mv<\/strong>) command on Mac is quite simple.<\/p>\n<p>To copy the contents of one file to another file, use the following command:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Command to copy contents of one file to another\">cp file1.extension file2.extension<\/pre>\n<\/div>\n<p>To copy a file from one location and move it to another location, use the following command:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true\" title=\"Command to copy a file from one location to another\">cp destination1 destination2.<\/pre>\n<\/div>\n<p>For example,<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Sample command to copy a file from one location to another\">cp ~\/Desktop\/samplefile.txt ~\/Documents\/samplefile.txt<\/pre>\n<\/div>\n<p>To copy folders or directories, we use the recursive flag (<strong>-R<\/strong>). The command is:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Command to copy a directory from one location to another\">cp \u2013R directory 1 directory2<\/pre>\n<\/div>\n<p>For example,<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Sample command to copy a directory from one location to another\">cp -R ~\/Desktop\/MyFolder ~\/Documents\/MyFolder<\/pre>\n<\/div>\n<p>To move a file from one location to another, use the following command:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Command to move a file from one location to another\">mv destination1 destination2.<\/pre>\n<\/div>\n<p>For example,<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Sample command to move a file from one location to another\">mv ~\/Desktop\/samplefile.txt ~\/Documents\/samplefile.txt<\/pre>\n<\/div>\n<p>To move folders or directories, we use the command:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Command to move a directory from one location to another\">mv directory 1 directory2.<\/pre>\n<\/div>\n<p>For example,<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Sample command to move a directory from one location to another\">mv ~\/Desktop\/MyFolder ~\/Documents\/MyFolder<\/pre>\n<\/div>\n<p>\n    \t\t\t\t<\/div>\r\n    \t\t\t<\/div><!-- \/ht-toggle-content -->\r\n    \t\t<\/div>\r\n    \t\t\n    \t\t<div class=\"hts-toggle  \"  >\r\n    \t\t\t<div class=\"hts-toggle__title\">The echo command <\/div>\r\n    \t\t\t<div class=\"hts-toggle__content\">\r\n    \t\t\t\t<div class=\"hts-toggle__contentwrap\">\r\n    \t\t\t\t\t<p>The <strong>echo<\/strong> command is used to display formatted static or dynamic text to the terminal window.<\/p>\n<p>To display static text, use the following command:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Command to display static content\">echo \u201cwrite content here\u201d<\/pre>\n<\/div>\n<p>Dynamic text includes displaying variables in the output. To display dynamic text that includes a variable, enter the following command:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Sample command to display dynamic content\">echo \u201cMy name is $username\u201d<\/pre>\n<\/div>\n<p>where you must define the variable <strong>$username<\/strong> beforehand. For example,<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Shell script to accept a value and print it\">!bin\/bash\r\nread -p \"What\u2019s your name?:\" username\r\necho \u201cHi $username\u201d<\/pre>\n<\/div>\n<p>Here, the <strong>read -p<\/strong> command takes input from the user and stores it in the variable <strong>$username<\/strong>. Then, the value stored in the <strong>$username<\/strong> variable is displayed using the <strong>echo<\/strong> command.<\/p>\n<p>\n    \t\t\t\t<\/div>\r\n    \t\t\t<\/div><!-- \/ht-toggle-content -->\r\n    \t\t<\/div>\r\n    \t\t\n    \t\t<div class=\"hts-toggle  \"  >\r\n    \t\t\t<div class=\"hts-toggle__title\">The list (ls) command <\/div>\r\n    \t\t\t<div class=\"hts-toggle__content\">\r\n    \t\t\t\t<div class=\"hts-toggle__contentwrap\">\r\n    \t\t\t\t\t<p>The <strong>ls<\/strong> command shows you the names of all the files and folders contained within the current directory. Adding additional parameters to this command can help give more information and simplify the process of searching for files and folders.<\/p>\n<p>To list files in a given directory, enter the following command:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Command to list all files in a directory\">ls directorypath<\/pre>\n<\/div>\n<p>For example,<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Sample command to list all files in Documents\">ls Documents\/Myfiles<\/pre>\n<\/div>\n<p>To list hidden files, use the following command:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Sample command to list hidden files in Documents\">ls \u2013a Documents\/Myfiles<\/pre>\n<\/div>\n<p>To list additional information on files, use the following command:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Sample command to list additional information on all files in Documents\">ls \u2013l Documents\/Myfiles<\/pre>\n<\/div>\n<p>To list information about a directory, use the following command:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Sample command to list information on the Documents directory\">ls \u2013d Documents\/Myfiles<\/pre>\n<\/div>\n<p>\n    \t\t\t\t<\/div>\r\n    \t\t\t<\/div><!-- \/ht-toggle-content -->\r\n    \t\t<\/div>\r\n    \t\t\n    \t\t<div class=\"hts-toggle  \"  >\r\n    \t\t\t<div class=\"hts-toggle__title\">The make directory (mkdir) and remove directory (rmdir) command<\/div>\r\n    \t\t\t<div class=\"hts-toggle__content\">\r\n    \t\t\t\t<div class=\"hts-toggle__contentwrap\">\r\n    \t\t\t\t\t<p>The <strong>mkdir<\/strong> command enables you to create new directories straight from the command line. The following is the syntax for the mkdir command:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Syntax for the mkdir command\">mkdir [OPTION] [DIRECTORY]<\/pre>\n<\/div>\n<p>To create a new folder in the current working directory, use the following command:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Command to create new folder in current working directory\">mkdir directoryname<\/pre>\n<\/div>\n<p>To create a new directory in a different location, specify the path along with the directory name.<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Command to create new folder in the specified location\">mkdir \/Myfolder\/newdir<\/pre>\n<\/div>\n<p>To create parent directories along with the new directories, include the parameter -p. For example,<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Command to create parent directories along with the new directory\">mkdir \/home\/scriptfiles\/samplefiles\/learnmkdir<\/pre>\n<\/div>\n<p>Here, if the directories mentioned do not exist, they are automatically created.<\/p>\n<p>\n    \t\t\t\t<\/div>\r\n    \t\t\t<\/div><!-- \/ht-toggle-content -->\r\n    \t\t<\/div>\r\n    \t\t\n    \t\t<div class=\"hts-toggle  \"  >\r\n    \t\t\t<div class=\"hts-toggle__title\">The open and remove (rm) command <\/div>\r\n    \t\t\t<div class=\"hts-toggle__content\">\r\n    \t\t\t\t<div class=\"hts-toggle__contentwrap\">\r\n    \t\t\t\t\t<p>The open command in macOS enables you to open a file or URL in your preferred application. On the other hand, the rm command is used to remove objects such as files and directories from the macOS system.<\/p>\n<p>To open a file or application, use the following command:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Command to open a file\">open filename.extension<\/pre>\n<\/div>\n<p>To remove a file from the macOS system, use the following command:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Command to remove a file\">rm filename.extension<\/pre>\n<\/div>\n<p>To force remove a file from the macOS system, use the following command:<\/p>\n<div class=\"copy-code-download\">\n<pre class=\"theme:github font:monospace font-size:15 line-height:32 toolbar:1 show-plain:3 lang:default decode:true \" title=\"Command to force remove a file\">rm -f filename.extension<\/pre>\n<\/div>\n<p>\n    \t\t\t\t<\/div>\r\n    \t\t\t<\/div><!-- \/ht-toggle-content -->\r\n    \t\t<\/div>\r\n    \t\t\n<p>You can also view our collection of sample scripts by visiting Hexnode\u2019s <a href=\"https:\/\/www.hexnode.com\/mobile-device-management\/help\/mac-shell-scripting-resources\/?utm_source=hexnode_blog_mac_shell_scripting&amp;utm_medium=referral&amp;utm_campaign=internal_link\" target=\"_blank\" rel=\"noopener\">sample script repository<\/a>.<\/p>\n<h2>Mac shell scripting best practices<\/h2>\n<p>Scripting can sometimes prove to be very complex to users, especially when writing and executing hundreds of lines of code. Without the right approach, you may get lost in the swamp of variables, subroutines and improperly formatted documentation. However, a few well-known scripting best practices may be able to help you out here.<\/p>\n<ul>\n<li>Document your code and ensure proper formatting<\/li>\n<li>Follow naming conventions. Ensure names do not clash with Shell commands<\/li>\n<li>Review your code in a test environment before deploying online<\/li>\n<\/ul>\n<blockquote class=\"wp-embedded-content\" data-secret=\"VdMioiX19Q\"><p><a href=\"https:\/\/www.hexnode.com\/blogs\/scripting-best-practices\/\">Scripting best practices every IT admin must follow<\/a><\/p><\/blockquote>\n<p><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Scripting best practices every IT admin must follow&#8221; &#8212; Hexnode Blogs\" src=\"https:\/\/www.hexnode.com\/blogs\/scripting-best-practices\/embed\/#?secret=X1JuSpxtEC#?secret=VdMioiX19Q\" data-secret=\"VdMioiX19Q\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<h2>The final note<\/h2>\n<p>As you can see, the features and functionalities provided by Mac shell scripting can enable IT administrators to accomplish nearly any sort of administrative task within a macOS environment. Furthermore, using a UEM solution like Hexnode to expedite the deployment and execution of Mac shell scripts allows IT teams to save a substantial amount of time and money, and helps make the remote execution of scripts on multiple devices a simple task.<\/p>\n<div class=\"signup_box\"><div class=\"signup_wrap_img\"><div class=\"signup-bg\" style=\"background-image:url(https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/01\/Apple-business-Essentials.png?format=webp)\"><\/div><\/div><div class=\"signup_wrap\"><h5>Need help managing macOS devices?<\/h5><p>Give Hexnode a go! Hexnode's industry-leading Unified Endpoint Management solution can easily help you meet all your device management needs.<\/p><a href=\"https:\/\/www.hexnode.com\/uem\/platform\/macos-device-management\/?utm_source=hexnode_blog_mac_shell_scripting&utm_medium=referral&utm_campaign=trial_sign_up_box\" class=\"hn-cta__blogs--signup-stripe\" target=\"_blank\"> TRY OUT HEXNODE<\/a><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Is Mac shell scripting difficult to learn? Well, to be honest, it depends. Shell scripting can prove to be quite challenging for individuals who do not know its pre-requisites. However, learning shell programming is actually rather simple. All you need are some good pointers. I bet, this guide can help you get started.<\/p>\n","protected":false},"author":29,"featured_media":17638,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2020,263],"tags":[4835,855],"class_list":["post-17540","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-beginners-guide","category-technical-deep-dives","tag-scripting","tag-mac-management","tab_group-immersive-reads"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>The ultimate guide to Mac shell scripting<\/title>\n<meta name=\"description\" content=\"Learn the basics of Mac shell scripting, including how to create and run a script, and review the common macOS shell commands, examples, and best practices\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.hexnode.com\/blogs\/the-ultimate-guide-to-mac-shell-scripting\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"The ultimate guide to Mac shell scripting\" \/>\n<meta property=\"og:description\" content=\"Learn the basics of Mac shell scripting, including how to create and run a script, and review the common macOS shell commands, examples, and best practices\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.hexnode.com\/blogs\/the-ultimate-guide-to-mac-shell-scripting\/\" \/>\n<meta property=\"og:site_name\" content=\"Hexnode Blogs\" \/>\n<meta property=\"article:published_time\" content=\"2022-03-24T11:55:42+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-05-31T11:20:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/The-ultimate-guide-to-Mac-shell-scripting.png?format=webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"688\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Eugene Raynor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Eugene Raynor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"23 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.hexnode.com\/blogs\/the-ultimate-guide-to-mac-shell-scripting\/\",\"url\":\"https:\/\/www.hexnode.com\/blogs\/the-ultimate-guide-to-mac-shell-scripting\/\",\"name\":\"The ultimate guide to Mac shell scripting\",\"isPartOf\":{\"@id\":\"https:\/\/www.hexnode.com\/blogs\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.hexnode.com\/blogs\/the-ultimate-guide-to-mac-shell-scripting\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.hexnode.com\/blogs\/the-ultimate-guide-to-mac-shell-scripting\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/The-ultimate-guide-to-Mac-shell-scripting.png?format=webp\",\"datePublished\":\"2022-03-24T11:55:42+00:00\",\"dateModified\":\"2023-05-31T11:20:53+00:00\",\"author\":{\"@id\":\"https:\/\/www.hexnode.com\/blogs\/#\/schema\/person\/ce1e9d70af4b7cbd61c20fc929eb6bcc\"},\"description\":\"Learn the basics of Mac shell scripting, including how to create and run a script, and review the common macOS shell commands, examples, and best practices\",\"breadcrumb\":{\"@id\":\"https:\/\/www.hexnode.com\/blogs\/the-ultimate-guide-to-mac-shell-scripting\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.hexnode.com\/blogs\/the-ultimate-guide-to-mac-shell-scripting\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.hexnode.com\/blogs\/the-ultimate-guide-to-mac-shell-scripting\/#primaryimage\",\"url\":\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/The-ultimate-guide-to-Mac-shell-scripting.png?format=webp\",\"contentUrl\":\"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/The-ultimate-guide-to-Mac-shell-scripting.png?format=webp\",\"width\":1280,\"height\":688,\"caption\":\"The ultimate guide to Mac shell scripting\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.hexnode.com\/blogs\/the-ultimate-guide-to-mac-shell-scripting\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.hexnode.com\/blogs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"The ultimate guide to Mac shell scripting\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.hexnode.com\/blogs\/#website\",\"url\":\"https:\/\/www.hexnode.com\/blogs\/\",\"name\":\"Hexnode Blogs\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.hexnode.com\/blogs\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.hexnode.com\/blogs\/#\/schema\/person\/ce1e9d70af4b7cbd61c20fc929eb6bcc\",\"name\":\"Eugene Raynor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.hexnode.com\/blogs\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2e596f796ef2a47682bbfe96b92e169056aa1307f640e50fbdf667ee417f3da2?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/2e596f796ef2a47682bbfe96b92e169056aa1307f640e50fbdf667ee417f3da2?s=96&d=mm&r=g\",\"caption\":\"Eugene Raynor\"},\"description\":\"Seeking what's there lurking over the horizon.\",\"sameAs\":[\"http:\/\/edwin\",\"edwin\"],\"url\":\"https:\/\/www.hexnode.com\/blogs\/author\/edwin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"The ultimate guide to Mac shell scripting","description":"Learn the basics of Mac shell scripting, including how to create and run a script, and review the common macOS shell commands, examples, and best practices","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.hexnode.com\/blogs\/the-ultimate-guide-to-mac-shell-scripting\/","og_locale":"en_US","og_type":"article","og_title":"The ultimate guide to Mac shell scripting","og_description":"Learn the basics of Mac shell scripting, including how to create and run a script, and review the common macOS shell commands, examples, and best practices","og_url":"https:\/\/www.hexnode.com\/blogs\/the-ultimate-guide-to-mac-shell-scripting\/","og_site_name":"Hexnode Blogs","article_published_time":"2022-03-24T11:55:42+00:00","article_modified_time":"2023-05-31T11:20:53+00:00","og_image":[{"width":1280,"height":688,"url":"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/The-ultimate-guide-to-Mac-shell-scripting.png?format=webp","type":"image\/png"}],"author":"Eugene Raynor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Eugene Raynor","Est. reading time":"23 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.hexnode.com\/blogs\/the-ultimate-guide-to-mac-shell-scripting\/","url":"https:\/\/www.hexnode.com\/blogs\/the-ultimate-guide-to-mac-shell-scripting\/","name":"The ultimate guide to Mac shell scripting","isPartOf":{"@id":"https:\/\/www.hexnode.com\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.hexnode.com\/blogs\/the-ultimate-guide-to-mac-shell-scripting\/#primaryimage"},"image":{"@id":"https:\/\/www.hexnode.com\/blogs\/the-ultimate-guide-to-mac-shell-scripting\/#primaryimage"},"thumbnailUrl":"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/The-ultimate-guide-to-Mac-shell-scripting.png?format=webp","datePublished":"2022-03-24T11:55:42+00:00","dateModified":"2023-05-31T11:20:53+00:00","author":{"@id":"https:\/\/www.hexnode.com\/blogs\/#\/schema\/person\/ce1e9d70af4b7cbd61c20fc929eb6bcc"},"description":"Learn the basics of Mac shell scripting, including how to create and run a script, and review the common macOS shell commands, examples, and best practices","breadcrumb":{"@id":"https:\/\/www.hexnode.com\/blogs\/the-ultimate-guide-to-mac-shell-scripting\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.hexnode.com\/blogs\/the-ultimate-guide-to-mac-shell-scripting\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hexnode.com\/blogs\/the-ultimate-guide-to-mac-shell-scripting\/#primaryimage","url":"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/The-ultimate-guide-to-Mac-shell-scripting.png?format=webp","contentUrl":"https:\/\/cdn.hexnode.com\/blogs\/wp-content\/uploads\/2022\/03\/The-ultimate-guide-to-Mac-shell-scripting.png?format=webp","width":1280,"height":688,"caption":"The ultimate guide to Mac shell scripting"},{"@type":"BreadcrumbList","@id":"https:\/\/www.hexnode.com\/blogs\/the-ultimate-guide-to-mac-shell-scripting\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.hexnode.com\/blogs\/"},{"@type":"ListItem","position":2,"name":"The ultimate guide to Mac shell scripting"}]},{"@type":"WebSite","@id":"https:\/\/www.hexnode.com\/blogs\/#website","url":"https:\/\/www.hexnode.com\/blogs\/","name":"Hexnode Blogs","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.hexnode.com\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.hexnode.com\/blogs\/#\/schema\/person\/ce1e9d70af4b7cbd61c20fc929eb6bcc","name":"Eugene Raynor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hexnode.com\/blogs\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/2e596f796ef2a47682bbfe96b92e169056aa1307f640e50fbdf667ee417f3da2?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2e596f796ef2a47682bbfe96b92e169056aa1307f640e50fbdf667ee417f3da2?s=96&d=mm&r=g","caption":"Eugene Raynor"},"description":"Seeking what's there lurking over the horizon.","sameAs":["http:\/\/edwin","edwin"],"url":"https:\/\/www.hexnode.com\/blogs\/author\/edwin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.hexnode.com\/blogs\/wp-json\/wp\/v2\/posts\/17540","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hexnode.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hexnode.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hexnode.com\/blogs\/wp-json\/wp\/v2\/users\/29"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hexnode.com\/blogs\/wp-json\/wp\/v2\/comments?post=17540"}],"version-history":[{"count":26,"href":"https:\/\/www.hexnode.com\/blogs\/wp-json\/wp\/v2\/posts\/17540\/revisions"}],"predecessor-version":[{"id":25869,"href":"https:\/\/www.hexnode.com\/blogs\/wp-json\/wp\/v2\/posts\/17540\/revisions\/25869"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hexnode.com\/blogs\/wp-json\/wp\/v2\/media\/17638"}],"wp:attachment":[{"href":"https:\/\/www.hexnode.com\/blogs\/wp-json\/wp\/v2\/media?parent=17540"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hexnode.com\/blogs\/wp-json\/wp\/v2\/categories?post=17540"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hexnode.com\/blogs\/wp-json\/wp\/v2\/tags?post=17540"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}