shell
Tags: computers
- shell uses the
readline2lib ^string1^string2does 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 callsdup2(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>&1works because> fileopens, file, kernel assigns it a fd, X, and then calls dup2(X, 1), so now FD 1 points to file2>&1shell calls dup2(1, 2), which looks at what 1 has
- but
ls 2>&1 > filedoesn’t work because it duplicates 1,FD 1 to 2, and then still remains it TTY. But > file then redirects back to file