首页 > 系统相关 >Linux shell script programming All In One

Linux shell script programming All In One

时间:2023-04-22 14:57:06浏览次数:38  
标签:profile bin shell script programming etc HOME bash

Linux shell script programming All In One

shell 脚本编程

image

Linux 系统中登录 shell 的时候,会从下面的 5 个启动文件里读取命令;

# 系统级,所有登录用户都会先启动这个文件
$ cat /etc/profile

# 用户级,按照Linux 发行版中实际存在的文件个数,依次进行启动
$ cat $HOME/.bash_profile
$ cat $HOME/.bashrc
$ cat $HOME/.bash_login
$ cat $HOME/.profile

shell types

shell 类型 / shell 种类

# $ which shell

$ which bash
$ which sh
$ which zsh

系统 截图
Raspberry Pi image
macOS image

启动文件

  1. 系统的 shell 启动配置文件 /etc/profile
$ cat /etc/profile

image

# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

if [ "$(id -u)" -eq 0 ]; then
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else
  PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games"
fi
export PATH

if [ "${PS1-}" ]; then
  if [ "${BASH-}" ] && [ "$BASH" != "/bin/sh" ]; then
    # The file bash.bashrc already sets the default PS1.
    # PS1='\h:\w\$ '
    if [ -f /etc/bash.bashrc ]; then
      . /etc/bash.bashrc
    fi
  else
    if [ "$(id -u)" -eq 0 ]; then
      PS1='# '
    else
      PS1='$ '
    fi
  fi
fi

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi
# 配置文件目录 `/etc/profile.d`
$ ls -al /etc/profile.d
  1. 用户的 shell 启动配置文件 $HOME/.profile
$ cat $HOME/.profile
# 等价于
$ cd ~ && cat .profile
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
	. "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi

echo "每次登录自动执行脚本 ✅"
bash /home/pi/Desktop/ip-program.sh

image

demos

(

标签:profile,bin,shell,script,programming,etc,HOME,bash
From: https://www.cnblogs.com/xgqfrms/p/17343088.html

相关文章

  • JavaScript奇技淫巧:Hook与反Hook
    JavaScript奇技淫巧:Hook与反Hook作者:专注于JS混淆加密的JShamanAPIHOOK技术,在PC时代曾盛行,是高端的技术。在JavaScript编程中,也可以应用APIHook技术实现不寻常的效果。例,evalhook:<html><script>//备份原window.eval函数var_eval=window.eval;//eval的hook函数window.eva......
  • 力扣——193.有效电话号码(shell)
    title:力扣——193.有效电话号码(shell)给定一个包含电话号码列表(一行一个电话号码)的文本文件file.txt,写一个bash脚本输出所有有效的电话号码。你可以假设一个有效的电话号码必须满足以下两种格式:(xxx)xxx-xxxx或xxx-xxx-xxxx。(x表示一个数字)你也可以假设每行前后没有......
  • 力扣——192.统计词频(shell)
    title:力扣——192.统计词频(shell)题目描述:写一个bash脚本以统计一个文本文件words.txt中每个单词出现的频率。为了简单起见,你可以假设:words.txt只包括小写字母和''。每个单词只由小写字母组成。单词间由一个或多个空格字符分隔。示例:假设words.txt内容如下:th......
  • 力扣——195.第十行(shell)
    title:力扣——195.第十行(shell)给定一个文本文件file.txt,请只打印这个文件中的第十行。示例:假设file.txt有如下内容:Line1Line2Line3Line4Line5Line6Line7Line8Line9Line10你的脚本应当显示第十行:Line10方法1:awk'NR==10'file.txt方法2:tai......
  • JavaScript加密库
    JavaScript加密库有很多,以下是一些常见的加密库:CryptoJS:一个纯JavaScript编写的加密库,提供了各种加密算法和编码方式的实现,包括对称加密、哈希函数、消息认证码、数字签名等。sjcl:一个JavaScript编写的加密库,提供了对称加密、公钥加密、哈希函数等,支持多种加密算法和模式。for......
  • TypeScript 的实用技巧
    TypeScript的实用技巧类型别名和接口:使用类型别名或接口可以定义复杂的数据类型,提高代码的可读性和可维护性。泛型:使用泛型可以提高代码的复用性,使代码更加灵活。非空断言操作符(!):当开发者确定一个变量或属性不为null或undefined时,可以使用非空断言操作符(!)来告诉编译......
  • window的shell怎么查看当前用户名
    在Windows的命令行界面下,可以使用%username%的环境变量来获取当前用户名。具体操作步骤如下:打开cmd命令提示符。可以使用Win+R组合键打开运行窗口,输入cmd命令,然后点击“确定”按钮。在命令提示符下输入echo%username%命令。按下回车键,在命令行界面中就可......
  • JavaScript学习笔记
    数组什么是数组?字面理解就是数字的组合其实不太准确,准确的来说数组是一个数据的集合也就是我们把一些数据放在一个盒子里面,按照顺序排好[1,2,3,'hello',true,false]这个东西就是一个数组,存储着一些数据的集合数据类型分类number/string/boolean/undefined/null/ob......
  • shell参数的个数用什么变量,怎么表示上一个运行的结果?两个数字相加,用什么
    Shell参数的个数可以使用特定的变量来表示,即$#变量。这个变量表示传递给当前shell脚本或函数的参数个数。例如,如果调用一个shell脚本,并向其传递了3个参数,那么在这个脚本中$#的值将为3。上一个运行的结果可以使用$?变量来表示。这个变量记录上一次命令的返回值(......
  • Vue JS项目 添加TypeScript
    VueJS项目添加TypeScript转载请注明来源谢谢git文件全部提交必须全部提交因为会改掉你的文件.很恶心.vue.config.js添加下面内容pages:{index:{entry:'src/main.js'}}项目根目录运行vueaddtypescript如果你英文可以那就忽略这一条.......