Added some starting scripts
parent
feb9d25b91
commit
20bf745c8e
@ -1,3 +1,21 @@
|
|||||||
# learn_bash
|
# learn_bash
|
||||||
|
|
||||||
A repo dedicated to getting better at Bash Shell scripting
|
A repo dedicated to getting better at Bash Shell scripting
|
||||||
|
|
||||||
|
## Commands
|
||||||
|
|
||||||
|
Add read and execute to a script using the DAC who symbols `u`, `g`, `o`. The ` a` symbol is equivalent to `ugo`. Both the read and execute bits must be set for the shell to read then execture a shell scripte.
|
||||||
|
```bash
|
||||||
|
chmod u+rx <script>
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Using absolute params here we are adding `rwx` to user, and `r` to group, and other.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
chmod 744 <script>
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
chown <user_id>:<group_id> <script>
|
||||||
|
```
|
@ -0,0 +1,15 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# $@ represents all of a scripts arguments and is useful to passing them to a command inside the script.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
VALUES=$@
|
||||||
|
|
||||||
|
echo The args are: $@
|
||||||
|
echo Storing a copy in VALUES
|
||||||
|
|
||||||
|
# -e enables interpretation of backslash escapes
|
||||||
|
echo -e "\nLets loop through our list of arguments"
|
||||||
|
for value in $@; do
|
||||||
|
echo The current argument is: $value
|
||||||
|
done
|
@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# Print something, then run ls
|
||||||
|
|
||||||
|
echo About to run the ls command
|
||||||
|
ls
|
@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# Bourne Shell Variables
|
||||||
|
#
|
||||||
|
#
|
||||||
|
echo Your script name is: $0
|
||||||
|
echo First argument: $1
|
||||||
|
echo Third argument: $3
|
@ -0,0 +1,19 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# The shell command `shift` can be used to remove the first argument $1
|
||||||
|
# and advance the rest of the arguments forward. $2 becomes $1, $3 becomes $2.
|
||||||
|
#
|
||||||
|
# Shiftex prints all three arguments by printing the first, shifting the remaining
|
||||||
|
# arguments, and repeating.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
#
|
||||||
|
|
||||||
|
# Print the number of arguments
|
||||||
|
echo You submitted $# arguments
|
||||||
|
|
||||||
|
echo Argument: $1
|
||||||
|
shift
|
||||||
|
echo Argument: $1
|
||||||
|
shift
|
||||||
|
echo Argument: $1
|
Loading…
Reference in New Issue