Giter Site home page Giter Site logo

shell_scripting's Introduction

Shell Scripting

some training and useful files for shell scripting

To make simple hello world bash script writ the following commands

create the file with:
touch hello_world.sh
decide the shell with:
echo "#! /bin/bash" >> hello_world.sh
echo "echo 'hello world'" >> hello_world.sh
then we have to change the permissions with:

NOTE: it's not good to add a permission to all users you may use 'chmod u+x' to change for the user only

chmod +x ./hello_world.sh
then call the file in the terminal with:
./hello_world.sh

Piplines

pipelines are where the input of a state is the output of the previous one and so on.
you can use the pipeline as follows cmd1 | cmd2
so imagin we have a file and want to get the unique values of it we can do this
sort [file name] | uniq

Some commands, such as tr, only accept "standard input" as input (not strings or filenames)
we use pipline for them as follows:
echo "Linux and shell scripting are awesome!" | tr "aeiou" "_"
OUTPUT: L_n_x _nd sh_ll scr_pt_ng r w_s_m!

It's also pretty useful filtering text or o/p of curl commands with grep as follows:
curl -s --location --request GET https://www.example.com | grep -oE ""price":\s*[0-9]?.[0-9]"

Metacharacters

# for comments
; for ending one command to start another in the same line
* indicates any number of charecters as in 'ls /bin/bas*'
? indicates 1 character as in 'ls /bin/?ash'
\ this is used before metacharactes to interpret them as text
"" must use \ before metacharacters while '' interpret all text as text

> redirect output to file and create one if not existed and override if it exists
>> append output to file
2> catchs error and writes them to a file
2>> catchs error and apend it to a file
< to pass file content to a standard i/p command

&(command) or `command` is used for replacing command with its o/p as in $ variable=$(pwd)
./random_file arg1 arg2 passing arguments to shell script

; runs commands sequentially
& runs commands parrelel

Scheduling jobs

cron allows u to do that
crond is the cron deamon which checks 'crontab files' every minute and submits job to cron
crontab is a table contains jobs and scedule data crontab -e opens the editor
U add commands describing jobs as follows:
m h dom mon dow command
all 5 position must have numeric or * for any

dow 0:sunday and so on

crontab -l gets the jobs and scedules

shell_scripting's People

Contributors

hmmk99 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.