Skip to main content
added 39 characters in body
Source Link

A mix of all the other answers, compatible with Mac (comm), Solaris (fname) and Linux (cmd):

ps -p$$ -o cmd="",comm="",fname="" 2>/dev/null | sed 's/^-//' | grep -oE '\w+' | head -n1

A mix of all the other answers, compatible with Mac and Linux:

ps -p$$ -o cmd="",comm="" 2>/dev/null | sed 's/^-//' | grep -oE '\w+' | head -n1

A mix of all the other answers, compatible with Mac (comm), Solaris (fname) and Linux (cmd):

ps -p$$ -o cmd="",comm="",fname="" 2>/dev/null | sed 's/^-//' | grep -oE '\w+' | head -n1
added 27 characters in body
Source Link

A mix of all the other answers, compatible with Mac and Linux:

ps -p$$ -o com,cmdcmd="",comm="" 2>/dev/null | sed 's/^-//' | grep -oE '\w+' | head -n1

A mix of all the other answers, compatible with Mac and Linux:

ps -p$$ -o com,cmd,comm="" 2>/dev/null | sed 's/^-//'

A mix of all the other answers, compatible with Mac and Linux:

ps -p$$ -o cmd="",comm="" 2>/dev/null | sed 's/^-//' | grep -oE '\w+' | head -n1
Source Link

A mix of all the other answers, compatible with Mac and Linux:

ps -p$$ -o com,cmd,comm="" 2>/dev/null | sed 's/^-//'