Home Ask Login Register

Developers Planet

Your answer is one click away!

SoulRebel February 2016

Understanding "bash" snippets

Could someone explain the following command for me please?

0<&112-;exec 112<>/dev/tcp/;sh <&112 >&112 2>&112


cdarke February 2016

See What are the uses of the exec command in shell scripts?


  • fd - file descriptor, an I/O channel identified by an integer
  • stdin - file descriptor zero, standard input, by default the terminal keyboard
  • stdout - file descriptor 1, standard output, by default the buffered terminal screen
  • stderr - file descriptor 2, standard error, by default the unbuffered terminal screen

Breaking this down:

# Move existing fd 122 to fd 0 (stdin), then close fd 112

# Open fd 112 for read/write on IP address and port
exec 112<>/dev/tcp/;  

# Run a POSIX shell (sh) taking stdin stdout and stderr to/from port 112
sh <&112 >&112 2>&112   

Post Status

Asked in February 2016
Viewed 1,158 times
Voted 10
Answered 1 times


Leave an answer

Quote of the day: live life