from Hacker News

My favorite/useful Shell Functions

by mr_o47 on 11/2/23, 2:16 AM with 1 comments

  • by chasil on 11/2/23, 3:14 PM

    The "function" keyword is defined in ksh88, but not in the POSIX shell definition for 1992 (there were a few reasons that much ksh functionality was removed). People call this a "bashism" because they do not realize that the syntax originated in Korn. Debian/Ubuntu use a POSIX system shell (dash) that does not recognize (almost) any korn/bash extended syntax.

    Here is my shell function to search for processes using shell patterns (these are not regular expressions):

      pps () { local a= b= c= IFS=$'\0'; ps ax | while read -r a
        do [ "$b" ] || c=1; for b; do case "$a" in *"$b"*) c=1;;
          esac; done; [ "$c" ] && printf '%s\n' "$a" && c=; done; }
    
    I have a fancy wrapper for .netrc password storage with SFTP, which is a little more extreme, if there is any interest.