{"id":3287,"date":"2024-10-09T15:19:29","date_gmt":"2024-10-09T08:19:29","guid":{"rendered":"https:\/\/audithink.com\/?p=3287"},"modified":"2026-09-01T14:25:54","modified_gmt":"2026-09-01T07:25:54","slug":"bash-script","status":"publish","type":"post","link":"https:\/\/audithink.com\/en\/blog\/bash-script\/","title":{"rendered":"What is Bash Script? Meaning, Basic Commands &amp; 16 Examples"},"content":{"rendered":"<p class=\"wp-block-paragraph\">Linux and macOS users may already know the word bash. You could also say bash provides <em>syntax<\/em> and a wide variety of built-in commands to manage files, processes, and also other tasks in the system.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Then for those who are not Linux or macOS users, what is bash? In order not to be too curious, let's Understand Together about what bash is.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Bash Script<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Bash <strong><a href=\"https:\/\/audithink.com\/en\/article\/script\/\" data-type=\"post\" data-id=\"3212\">script<\/a><\/strong> is a set of commands organized in a text file and executed using Bash (Bourne Again SHell), a command-line interpreter in Linux or Unix operating systems.\u00a0<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Used for automation of tasks that are often performed in the system, such as file Management, Process Management, networking, and so forth.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A Shell is a program that provides a command-line interface for interacting with the operating system. Bash script allows the automation of various tasks that are usually performed manually through this interface, such as Directory navigation, file creation, or program execution.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Every bash script starts with a shebang (#!\/bin \/ bash), which indicates the location of the Bash interpreter and tells the system to use Bash in executing that script. Inside the script file, a programmer can write down the same commands as those entered in the terminal.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Variables in bash script are used to store data in the form of text or Numbers, without the need for a specific data type declaration. In addition, it also supports a function that allows grouping a number of commands into a single block that can be recalled as needed.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Benefits Of Bash Script<\/h2>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img fetchpriority=\"high\" decoding=\"async\" width=\"2352\" height=\"1568\" src=\"https:\/\/audithink.com\/wp-content\/uploads\/2024\/10\/ezgif-1-a19e61f2f7_11zon.webp\" alt=\"picture of the person doing the task\" class=\"wp-image-3290\" style=\"width:602px;height:auto\" title=\"\" srcset=\"https:\/\/audithink.com\/wp-content\/uploads\/2024\/10\/ezgif-1-a19e61f2f7_11zon.webp 2352w, https:\/\/audithink.com\/wp-content\/uploads\/2024\/10\/ezgif-1-a19e61f2f7_11zon-300x200.webp 300w, https:\/\/audithink.com\/wp-content\/uploads\/2024\/10\/ezgif-1-a19e61f2f7_11zon-1024x683.webp 1024w, https:\/\/audithink.com\/wp-content\/uploads\/2024\/10\/ezgif-1-a19e61f2f7_11zon-768x512.webp 768w, https:\/\/audithink.com\/wp-content\/uploads\/2024\/10\/ezgif-1-a19e61f2f7_11zon-1536x1024.webp 1536w, https:\/\/audithink.com\/wp-content\/uploads\/2024\/10\/ezgif-1-a19e61f2f7_11zon-2048x1365.webp 2048w, https:\/\/audithink.com\/wp-content\/uploads\/2024\/10\/ezgif-1-a19e61f2f7_11zon-18x12.webp 18w\" sizes=\"(max-width: 2352px) 100vw, 2352px\" \/><figcaption class=\"wp-element-caption\">Bash Script (sumber: Pexels.com)<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">With the bash script certainly also provides many benefits for its users. Then what are the benefits? Here are some of the benefits of bash script are among others:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Task Automation<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Allows automation of repetitive tasks. This is especially beneficial in System Administration, where routine tasks such as data backup, system updating, or file management can be performed automatically, thus saving time and reducing the possibility of human error.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Portability<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Scripts written in bash can be run on a variety of platforms and operating systems that support Bash, such as Unix, Linux, macOS, and even Windows through emulators or virtual machines. Thus, the same script can be used in different environments without the need for significant modifications.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. Flexibility and customization<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The script is very flexible and can be customized to meet specific needs. These scripts can be easily modified and combined with other programming languages or utilities to create more powerful solutions according to specific needs.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. Easy access and editing<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">No special tools or software are required to create bash scripts. This File can be edited using any text editor, and most operating systems come with a built-in shell interpreter, making it easily accessible to anyone.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5. Integration with other tools and applications<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">It can be integrated with various tools and applications, such as databases, web servers, and cloud services. This enables more complex automation and more sophisticated system management.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6. Easy to debug<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">It is relatively easy to analyze and repair when problems occur. Most shells provide built-in debugging and error reporting tools that help in quick identification and resolution of problems.<\/p>\n\n\n\t\t<div data-elementor-type=\"section\" data-elementor-id=\"5427\" class=\"elementor elementor-5427\" data-elementor-post-type=\"elementor_library\">\r\n\t\t\t<div class=\"elementor-element elementor-element-c693698 e-flex e-con-boxed e-con e-parent\" data-id=\"c693698\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-f131bf4 cta-banner-article elementor-widget elementor-widget-image\" data-id=\"f131bf4\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"https:\/\/audithink.com\/en\/demo\/?utm_source=blog&#038;utm_medium=cta-banner&#038;utm_campaign=request-demo-cta-banner&#038;utm_content=request-demo-aplikasi-audit-banner\">\n\t\t\t\t\t\t\t<img decoding=\"async\" width=\"2400\" height=\"800\" src=\"https:\/\/audithink.com\/wp-content\/uploads\/2026\/07\/audithink-banner-v3-photo.webp\" class=\"attachment-full size-full wp-image-5428\" alt=\"cta banner campaign\" srcset=\"https:\/\/audithink.com\/wp-content\/uploads\/2026\/07\/audithink-banner-v3-photo.webp 2400w, https:\/\/audithink.com\/wp-content\/uploads\/2026\/07\/audithink-banner-v3-photo-300x100.webp 300w, https:\/\/audithink.com\/wp-content\/uploads\/2026\/07\/audithink-banner-v3-photo-1024x341.webp 1024w, https:\/\/audithink.com\/wp-content\/uploads\/2026\/07\/audithink-banner-v3-photo-768x256.webp 768w, https:\/\/audithink.com\/wp-content\/uploads\/2026\/07\/audithink-banner-v3-photo-1536x512.webp 1536w, https:\/\/audithink.com\/wp-content\/uploads\/2026\/07\/audithink-banner-v3-photo-2048x683.webp 2048w, https:\/\/audithink.com\/wp-content\/uploads\/2026\/07\/audithink-banner-v3-photo-18x6.webp 18w\" sizes=\"(max-width: 2400px) 100vw, 2400px\" title=\"\">\t\t\t\t\t\t\t\t<\/a>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\r\n\t\t\n\n\n\n<h2 class=\"wp-block-heading\">Basic Bash Script Commands<\/h2>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><img decoding=\"async\" width=\"1024\" height=\"683\" src=\"https:\/\/audithink.com\/wp-content\/uploads\/2024\/10\/ezgif-1-1d5917c94c_11zon-1024x683.webp\" alt=\"sample script\" class=\"wp-image-3289\" style=\"width:652px;height:auto\" title=\"\" srcset=\"https:\/\/audithink.com\/wp-content\/uploads\/2024\/10\/ezgif-1-1d5917c94c_11zon-1024x683.webp 1024w, https:\/\/audithink.com\/wp-content\/uploads\/2024\/10\/ezgif-1-1d5917c94c_11zon-300x200.webp 300w, https:\/\/audithink.com\/wp-content\/uploads\/2024\/10\/ezgif-1-1d5917c94c_11zon-768x512.webp 768w, https:\/\/audithink.com\/wp-content\/uploads\/2024\/10\/ezgif-1-1d5917c94c_11zon-1536x1024.webp 1536w, https:\/\/audithink.com\/wp-content\/uploads\/2024\/10\/ezgif-1-1d5917c94c_11zon-2048x1365.webp 2048w, https:\/\/audithink.com\/wp-content\/uploads\/2024\/10\/ezgif-1-1d5917c94c_11zon-18x12.webp 18w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Bash Script (sumber: Pexels.com)<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Here are some basic bash script commands you need to understand.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. echo<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This first basic bash script command serves to display text on the terminal screen, usually used to show the output of the script.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. read<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The second basic bash script command allows scripts to take input from users, this command is often used to enter data into variables.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. if, else, elif<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The third basic bash script command is a control structure used to make conditional decisions. This structure allows the script to execute different commands based on specific conditions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. for loop<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The fourth basic bash script command is useful for repeating a series of commands a specified number of times, serving to iterate through a list of items or a range of numbers.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5. while loop<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The basic bash script command is a loop that lasts as long as the specified condition remains true, applied to a process that needs to be repeated until the specified condition is met.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6. case<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The basic command of bash script which is a control structure to perform selection based on a certain pattern, is often used to handle various cases in a single command block.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">7. function<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">These basic commands define functions (blocks of commands that can be called many times in a script), these commands help in the organization and management of complex code.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">8. chmod<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This basic command changes the access permissions for a file or directory, essential to control who can read, write or run the file.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">9. \/ (pipe)<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Basic commands stream the output from one command to another, allowing concatenation of multiple commands in a single line.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">10. &gt; and &gt;&gt;<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The fourth basic bash script command is useful for repeating a series of commands a specified number of times, serving to iterate through a list of items or a range of numbers.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">11. grep<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This basic command searches for patterns in text, useful for finding specific strings in files or command output.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">12. cut<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">As the name implies, this basic command cuts a part of each line either in the file or in the output, being used to extract a specific part of the text.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">13. cd<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This basic command serves to change the current directory, this command to navigate in the system a file.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">14. mkdir &amp; rmdir<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This basic command is used to create and delete directories. 'mkdir \u2018to create a new directory, while\u2019 rmdir' to delete an empty directory.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">15. rm<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">This basic command is useful for deleting files or directories, this command can be said to be important in file management.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">16. cp &amp; mv<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, this command is used to copy and move files or directories. 'cp \u2018is useful for copying, while\u2019 mv' is useful for moving or renaming files.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Bash Script Example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">After knowing about understanding and some basic bash script commands, here are some examples of bash scripts, among others:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Simple Bash Script Example<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">#!\/bin \/ bash&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"># Script to print messages&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">echo \u201cHello, World!\u201d<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Explanation:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>#!\/bin \/ bash: Shebang, indicating that this script will be executed using Bash.<\/li>\n\n\n\n<li>echo \u201cHello, World!\": The echo command is used to print text to the screen.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">To run the script above, there are several steps you must do, here is the explanation.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Simpan script di file, misalnya hello.sh.<\/li>\n\n\n\n<li>Grant execution permission with the command:<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">chmod +x hello.sh<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Run the script with the command:. \/hello.sh<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. Examples Of Complex Bash Scripts<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">#!\/bin \/ bash<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"># Script accepts name input<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">echo \" enter your name.\u201d<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">read the name<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">echo \u201chello, $name. Welcome to Bash scripting!\u201d<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When running this script, the user will be prompted to enter a name, and then the script will print a customized message with that name.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">FAQ About <em>Bash Script<\/em><\/h2>\n\n\n\n<details class=\"wp-block-details is-layout-flow wp-block-details-is-layout-flow\"><summary><strong>What is <em>bash script<\/em>?<\/strong><\/summary>\n<p class=\"wp-block-paragraph\"><em>Bash script<\/em> is a series of commands assembled in a text file and run using Bash (<em>Bourne Again SHell<\/em>), <em>a command-line interpreter<\/em> on Linux or Unix operating systems. Its purpose is to automate tasks such as file handling, process management, and network configuration.<\/p>\n<\/details>\n\n\n\n<details class=\"wp-block-details is-layout-flow wp-block-details-is-layout-flow\"><summary><strong>What is <em>shebang<\/em> in <em>bash script<\/em>?<\/strong><\/summary>\n<p class=\"wp-block-paragraph\"><em>Shebang<\/em> is the line <code>#!\/bin \/ bash<\/code> at the start of a script that shows the location of <em>interpreter<\/em> Bash and tells the system to use Bash when running that script.<\/p>\n<\/details>\n\n\n\n<details class=\"wp-block-details is-layout-flow wp-block-details-is-layout-flow\"><summary><strong>What are the benefits of using a <em>bash script<\/em>?<\/strong><\/summary>\n<p class=\"wp-block-paragraph\">Automating repetitive tasks such as data <em>backup<\/em> and system updates; portability across any platform supporting Bash; flexibility and ease of customisation; easy access and editing through any text editor; integration with <em>database<\/em> and other services; <em>cloud<\/em>and straightforward <em>debugging<\/em>.<\/p>\n<\/details>\n\n\n\n<details class=\"wp-block-details is-layout-flow wp-block-details-is-layout-flow\"><summary><strong>What are the basic commands in <em>bash script<\/em>?<\/strong><\/summary>\n<p class=\"wp-block-paragraph\">Sixteen basic commands, among them <code>echo<\/code> to display text, <code>read<\/code> to take input, the control structures <code>if<\/code>, <code>else<\/code>, and <code>elif<\/code>, the loops <code>for<\/code> and <code>while<\/code>, <code>case<\/code>, <code>function<\/code>, <code>chmod<\/code>, <em>pipe<\/em> (<code>|<\/code>), <code>grep<\/code>, <code>cut<\/code>, <code>cd<\/code>, <code>mkdir<\/code> and <code>rmdir<\/code>, <code>rm<\/code>, as well as <code>cp<\/code> and <code>mv<\/code>.<\/p>\n<\/details>\n\n\n\n<details class=\"wp-block-details is-layout-flow wp-block-details-is-layout-flow\"><summary><strong>How do variables and functions work in <em>bash script<\/em>?<\/strong><\/summary>\n<p class=\"wp-block-paragraph\">Variables are used to store data \u2014 text or numbers \u2014 without having to declare a particular data type. Functions allow a set of commands to be grouped into one block that can be called again as needed, keeping the code better organised.<\/p>\n<\/details>\n\n\n\n<details class=\"wp-block-details is-layout-flow wp-block-details-is-layout-flow\"><summary><strong>What does an example of a <em>bash script<\/em> look like?<\/strong><\/summary>\n<p class=\"wp-block-paragraph\">The simplest script consists of a <em>shebang<\/em> <code>#!\/bin \/ bash<\/code> followed by the command <code>echo \"Hello, World!\"<\/code> to print text to the screen. The script then needs execute permission before it can be run from the terminal.<\/p>\n<\/details>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In this article, we take the conclusion that, bash script is a collection of commands executed through bash for automation of various tasks in Unix or Linux based operating systems.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">With features such as variables, functions, and flow control, Bash scripts allow users to automate routine tasks, such as file Management, Process Management, and System Administration.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Its main benefits include automation, portability, flexibility, as well as integration with other tools and applications. A basic understanding of Bash commands such as echo, if-else, for, and grep, provides a solid foundation for creating simple to complex scripts.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Lastly, if you are looking for the best audit app, trust Audithink. The features of the application that we offer are in the form of risk offerings, Planning, Monitoring, and much more. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/audithink.com\/en\/contact\/\"><strong>Contact Contact Us<\/strong><\/a> to obtain other information or consult on the needs of your audit team.<\/p>","protected":false},"excerpt":{"rendered":"<p>A Bash script provides flexible syntax for managing files, processes, and system tasks. Read on for what it means, the basic commands, and 16 examples of use.<\/p>","protected":false},"author":11,"featured_media":3288,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"rank_math_title":"Apa itu Bash Script? Arti, Perintah Dasar &amp; 16 Contohnya","rank_math_description":"Bash script adalah serangkaian perintah yang disusun dalam file teks dan dijalankan menggunakan Bash (Bourne Again SHell).  Baca lainnya di sini","rank_math_canonical_url":"","_yoast_wpseo_title":"","_yoast_wpseo_metadesc":"","_yoast_wpseo_canonical":"","footnotes":""},"categories":[15],"tags":[29],"class_list":["post-3287","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-teknologi-aplikasi-audit"],"acf":[],"_links":{"self":[{"href":"https:\/\/audithink.com\/en\/wp-json\/wp\/v2\/posts\/3287","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/audithink.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/audithink.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/audithink.com\/en\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/audithink.com\/en\/wp-json\/wp\/v2\/comments?post=3287"}],"version-history":[{"count":4,"href":"https:\/\/audithink.com\/en\/wp-json\/wp\/v2\/posts\/3287\/revisions"}],"predecessor-version":[{"id":5898,"href":"https:\/\/audithink.com\/en\/wp-json\/wp\/v2\/posts\/3287\/revisions\/5898"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/audithink.com\/en\/wp-json\/wp\/v2\/media\/3288"}],"wp:attachment":[{"href":"https:\/\/audithink.com\/en\/wp-json\/wp\/v2\/media?parent=3287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/audithink.com\/en\/wp-json\/wp\/v2\/categories?post=3287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/audithink.com\/en\/wp-json\/wp\/v2\/tags?post=3287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}