User Tools

Site Tools


wiki:2018programming_in_bash

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
wiki:2018programming_in_bash [2018/07/16 17:25]
david created
wiki:2018programming_in_bash [2018/07/26 13:18]
david [Final Steps]
Line 4: Line 4:
 Let's build on our previous work to make a full-fledged script. Let's build on our previous work to make a full-fledged script.
  
-Now, let's make it executable. That means that we don't have to type "​bash"​ anymore. This will be important when we try to use it as a command.+Now, let's make it executable. That means that we don't have to type "​bash"​ anymore. This will be important when we use our script ​as a command
 + 
 +For this part,  
 +  - open your Terminal 
 +  - cd to Bash_Scripts 
 +  - type '​ls'​ to see your previous work 
 + 
 +So far, the only way to run our script is by 
 +<code bash> 
 +$ bash revComp 
 +</​code>​ 
 +and we must be in the same directory as revComp. 
 + 
 +What we're really doing is //​executing//​ bash, and giving our file as the argument to the bash program. 
 + 
 +We're going to make a change to the permissions so we can execute our script directly. 
 + 
 +===== Executable permissions ===== 
 + 
 +It's not executable yet. We can easily make it executable with %%chmod%%. 
 + 
 +<code bash> 
 +$ ls -l revComp 
 +-rw-r--r-- 1 fileowner filegroupname 62 Jul 16 12:32 revComp 
 +$ chmod 755 hello_world 
 +$ ls -l hello_world  
 +-rwxr-xr-x 1 fileowner filegroupname 62 Jul 16 12:32 revComp 
 +</​code>​ 
 +8-O Notice the **//x//** in the 4<​sup>​th</​sup>,​ 7<​sup>​th</​sup>,​ and 10<​sup>​th</​sup>​ positions. This means that the file has execute permissions for the file owner, the file group, and everyone, respectively. 
 + 
 +:!: Two common permission settings for scripts are:  
 +  * 755 means everyone can execute,  
 +  * 700 means only the file owner can execute. 
 + 
 +To learn more about file permissions and these numbers, see [[wiki:​permissions|file permissions]].
  
 <code bash> <code bash>
Line 21: Line 55:
  
 ===== Final Steps ===== ===== Final Steps =====
 +
 +
 Currently, our script only works in the directory %%~/​Bash_Scripts%%. Currently, our script only works in the directory %%~/​Bash_Scripts%%.
  
Line 56: Line 92:
 </​code>​ </​code>​
  
-3. Copy the finished script to the new directory. Use the TAB key to help you not type so much.+3. Copy the finished script to the new directory. Use TAB-completion ​to help you not type so much.
  
 <code bash> <code bash>
Line 68: Line 104:
 4.  4. 
  
-===== Executable permissions ===== 
  
-It's not executable yet. We can easily make it executable with %%chmod%%. 
- 
-<code bash> 
-$ ls -l hello_world 
--rw-r--r-- 1 fileowner filegroupname 62 Jul 16 12:32 hello_world 
-$ chmod 755 hello_world 
-$ ls -l hello_world ​ 
--rwxr-xr-x 1 fileowner filegroupname 62 Jul 16 12:32 hello_world 
-</​code>​ 
-8-O Notice the **//x//** in the 4<​sup>​th</​sup>,​ 7<​sup>​th</​sup>,​ and 10<​sup>​th</​sup>​ positions. This means that the file has execute permissions for the file owner, the file group, and everyone, respectively. 
- 
-:!: Two common permission settings for scripts are:  
-  * 755 means everyone can execute, ​ 
-  * 700 means only the file owner can execute. 
- 
-To learn more about file permissions and these numbers, see [[wiki:​permissions|file permissions]]. 
wiki/2018programming_in_bash.txt · Last modified: 2018/07/26 13:18 by david