[root@server mnt]# source /root/.bash_profile ##重新加载骨配置文件
[root@server mnt]# sh test.sh
1
[root@server mnt]# su - student ##切换到其他用户
Last login: Thu May 11 20:23:54 EDT 2017 on pts/0
[student@server ~]$ sh /mnt/test.sh ##无法调用脚本
(3)系统级变量
[root@server mnt]# vim /etc/profile
[root@server mnt]# source /etc/profile
[root@server mnt]# sh /mnt/test.sh
1
[root@server mnt]# su - student
Last login: Sat May 18 12:53:51 EDT 2019 on pts/0
[student@server ~]$ sh /mnt/test.sh ##普通用户可以使用此脚本
1
[root@server mnt]# vim file.sh
[root@server mnt]# cat file.sh
#!/bin/bash
echo '$$' is $$
echo '$0' is $0
echo '$1' is $1
echo '$2' is $2
echo '$3' is $3
echo '$*' is $*
echo '$@' is $@
echo '$#' is $#
[root@server mnt]# chmod +x file.sh
[root@server mnt]# sh file.sh 1 2 3 4
$$ is 3326
$0 is file.sh
$1 is 1
$2 is 2
$3 is 3
$* is 1 2 3 4
$@ is 1 2 3 4
$# is 4
[root@server mnt]# vim luck.sh
[root@server mnt]# cat luck.sh
#!/bin/bash
for i in "$*"
do
echo $i
done
[root@server mnt]# sh -x luck.sh 1 2 3 4
+ for i in '"$*"'
+ echo 1 2 3 4
1 2 3 4
[root@server mnt]# vim luck.sh
[root@server mnt]# cat luck.sh
#!/bin/bash
for i in "$@"
do
echo $@
done
[root@server mnt]# sh -x luck.sh 1 2 3 4
+ for i in '"$@"'
+ echo 1 2 3 4
1 2 3 4
+ for i in '"$@"'
+ echo 1 2 3 4
1 2 3 4
+ for i in '"$@"'
+ echo 1 2 3 4
1 2 3 4
+ for i in '"$@"'
+ echo 1 2 3 4
1 2 3 4
[root@server mnt]# read -p "Plese input a word:" WORD
Plese input a word:haha
[root@server mnt]# echo $WORD
haha
[root@server mnt]# read -p "Plese input a word:" -s WORD
Plese input a word:
[root@server mnt]# echo $WORD
westos
四.Linux中命令别名的设定 1.仅在当前环境中使用,在其他环境中不可以使用
[root@server mnt]# shijian
bash: shijian: command not found...
[root@server mnt]# alias shijian='date'
[root@server mnt]# shijian
Sat May 18 14:14:32 EDT 2019
2.某一用户可以永久使用别名
[root@server mnt]# vim /root/.bashrc
[root@server mnt]# source /root/.bashrc
[root@server mnt]# shijian ##当前用户可用
Sat May 18 14:17:28 EDT 2019
[root@server mnt]# su - student
Last login: Sat May 18 14:10:33 EDT 2019 on pts/0
[student@server ~]$ shijian ##其他用户不可用
bash: shijian: command not found...
3.设定系统中的用户均可以使用此别名
[root@server student]# vim /etc/bashrc
[root@server student]# source /etc/bashrc
[root@server student]# shijian
Sat May 18 14:23:22 EDT 2019
[root@server student]# su - student
Last login: Sat May 18 14:21:49 EDT 2019 on pts/0
[student@server ~]$ shijian
Sat May 18 14:23:33 EDT 2019
4.取消系统中别名的设定
[root@server student]# vim /etc/bashrc ##删除系统中的别名设定
[root@server student]# vim /root/.bashrc ##删除用户的别名设定
[root@server student]# unalias shijian ##删除当前环境的别名设定
[root@server student]# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[root@server mnt]# sh check_file.sh
Please input filename:/etc/passwd
/etc/passwd is a common file
Please input filename:/mnt
/mnt is a directory
Please input filename:exit