Pages

Monday, September 18, 2023

shell bultin vs external shell

 It is advised that "which" is not a native (builtin) command in Linux. We might use the command "type" to check its origin.

In Bash, some commands such as "hash", "type", and "command -v" are recommended over "which" to utilised in case you want to check whether a particular application has been installed on the machine or not.

By the way, you might use "cmdOut, err := exec.Command("sh", "-c", input).Output()" in Golang to run external shell. I write a simple utility in Golang as bellow to do that:

If you write exec.Command("ls"), it will surely work but exec.Command("type type") it will throw an error saying that "type" is not a command. 

Here is the detailed error: "exec: "type netstat": executable file not found in $PATH".

Changing to "exec.Command("sh", "-c", "type netstat").Output() it will work perfectly.