عجفت الغور

shell

Tags: computers

  • shell uses the readline2 lib
  • ^string1^string2 does word replace
    • Note that this doesn’t work in fish
  • !^ and !$ map to the first and last arguments of the latest command, respectively

Redirects

  • Shells processes redirects in POSIX by left to right: https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html#:~:text=The%20shell%20performs%20redirection%20(see,operands%20from%20the%20parameter%20list.
  • Which means orders do matter
  • When the shell sees Wjhe, it doesn’t create a symbolic link or dynamic reference call, it calls dup2(1,2)
    • dup2(oldfd, newfd) copies the file description (internal kernel pointer to open file) from oldfd ot newfd. Once it’s copied,. it doesn’t change the oldfd.
  • so ls > file 2>&1 works because
    • > file opens, file, kernel assigns it a fd, X, and then calls dup2(X, 1), so now FD 1 points to file
    • 2>&1 shell calls dup2(1, 2), which looks at what 1 has
  • but ls 2>&1 > file doesn’t work because it duplicates 1,FD 1 to 2, and then still remains it TTY. But > file then redirects back to file

Links to this note