Featured image of post Learning Shell Programming 1

Learning Shell Programming 1

01.Shell programming

Shell create and running

  1. The first line of the shell script is to set the shell interpter.
1
#!/bin/bash
  1. source script-name or “.” is to read or load which shell variable in the shell script.

  2. sequeues to load variables in the shell scripts . When we use command source ./file or . file to load varialbe. the shell will excuted in the same shell as we just run it in the same shell.

when we run sh shell_script.sh, it will open a new shell interpter to run it. when the shell excute end. the shell will ended. and the variable will not be read into current we excuted.

shell tips

  1. Indicator the shell interpter at the 1st line of the shell script
1
#!/bin/bash

or

1
#!/bin/sh
  1. shell Add more informaton in the comments
1
2
3
4
5
# Date: 17:25 CST 2023-2-3
# Author: Create by Steve Dong
# Blog: https://echowings.github.io
# Description: This scriptes funciton is ...
# Version 1.0

environment variable initial and loading config file sequques

  • system user login the shell
graph TD A[ /etc/profile ] --> B( /etc/profile.d ) B --> C[ $HOME/.bash_profile ] C --> D[ $HOME/.bashrc ] D --> E[ /etc/bashrc ]
  • nolgin interactive shell
  • runing script without interactive shell
graph TD A[ $HOME/.bashrc ] --> B[ /etc/bashrc ]
CC BY-NC-ND
Last updated on Nov 08, 2024 12:49 UTC
Built with Hugo
Theme Stack designed by Jimmy