Skip navigation
TIL: Bash has a nice hook to intercept the exact line the user entered.
0:00 / 0:30

TIL: Bash has a nice hook to intercept the exact line the user entered.

Ivan Velichko

@iximiuz76K followers

Visit on X
126 likesDownloadOriginal post

13,694 views

TIL: Bash has a nice hook to intercept the exact line the user entered. The idea is rather simple. Bash uses readline() to get the final user input, and attaching a u(ret)probe to it lets you see the whole string. Immediately taught ShellGym this trick:

3 Comments

Comments from the original post on X (Twitter)

  • Buswe's profile picture

    @buswe_com

    bpftrace -e 'uretprobe:/bin/bash:readline { printf("%s\n", str(retval)); }' streams every line live, no bashrc changes.

  • Nick Hirras's profile picture

    @NickHirras

    Classic bpftrace bashreadline trick. Gotcha: Ubuntu links readline statically into bash, so you probe /bin/bash:readline, not On distros that link it dynamically the probe target flips.

  • Daði Árnason's profile picture

    @DadiArna

    6fðð688hh Gy