[LINUX] Executing system commands in Ruby

When I was writing Ruby, I wanted to execute a system command in a script, so I looked it up.

Kernel#system

This is the simplest way to write.

system("ls")
# => true

The command execution result is returned to the standard output. The return value of the method is as follows

--true When the command succeeds -- false When the command fails --When there is no nil command

Kernel#`

It is used when you want the command execution result as a return value.

`ls`
# => "Applications\nLibrary\nSystem\nUsers\nVolumes\nbin\ncores\ndev\netc\nhome\nopt\nprivate\nsbin\ntmp\nusr\nvar\n"

It seems that the return value is a character string type.

%x||There seems to be an alias called.

reference

Recommended Posts

Executing system commands in Ruby
Rock-paper-scissors in Ruby
Run shell commands in python
Frequently used commands in virtualenv
Check for external commands in python
8 Frequently Used Commands in Python Django
Handle dates in Linux bash commands