shell
Command not found when comparing string
I’m sure this has come up before, but — [ is actually a command. You need a space after the [ in order for the shell to find it.
How to run SWI-Prolog from the command line?
ISO directive: initialization. This should work. :- initialization main. main :- write(‘Hello World\n’). edit sorry, I skipped over most interesting details. Here is a sample script, let’s say saved in ~/test/main.pl #!/home/carlo/bin/swipl -f -q :- initialization main. main :- current_prolog_flag(argv, Argv), format(‘Hello World, argv:~w\n’, [Argv]), halt(0). and made executable with chmod +x ~/test/main.pl then I … Read more
How to run commands via NodeJS child process?
Sending a newline \n will exectue the command. .end() will exit the shell. I modified the example to work with bash as I’m on osx. var terminal = require(‘child_process’).spawn(‘bash’); terminal.stdout.on(‘data’, function (data) { console.log(‘stdout: ‘ + data); }); terminal.on(‘exit’, function (code) { console.log(‘child process exited with code ‘ + code); }); setTimeout(function() { console.log(‘Sending stdin … Read more
How to add text at the end of each line in unix
There are many ways: sed: replace $ (end of line) with the given text. $ sed ‘s/$/ | COUNTRY/’ file india | COUNTRY sudan | COUNTRY japan | COUNTRY france | COUNTRY awk: print the line plus the given text. $ awk ‘{print $0, “| COUNTRY”}’ file india | COUNTRY sudan | COUNTRY japan | … Read more
How do I determine if a web page exists with shell scripting?
Under a *NIX, you can use curl to issue a simple HEAD request (HEAD only asks for the headers, not the page body): curl –head http://myurl/ Then you can take only the first line, which contains the HTTP status code (200 OK, 404 Not Found, etc.): curl -s –head http://myurl/ | head -n 1 And … Read more
How to run a shell script on every request?
You can execute a shell script via Lua code from the nginx.conf file to achieve this. You need to have the HttpLuaModule to be able to do this. Here’s an example to do this. location /my-website { content_by_lua_block { os.execute(“/bin/myShellScript.sh”) } }
${BASH_SOURCE[0]} equivalent in zsh?
${BASH_SOURCE[0]} equivalent in zsh is ${(%):-%N}, NOT $0(as OP said, the latter failed in .zshrc) Here % indicates prompt expansion on the value, %N indicates “The name of the script, sourced file, or shell function that zsh is currently executing, whichever was started most recently. If there is none, this is equivalent to the parameter … Read more
Which terminal command to get just IP address and nothing else?
You can write a script that only return the IP like: /sbin/ifconfig eth0 | grep ‘inet addr’ | cut -d: -f2 | awk ‘{print $1}’ For MAC: ifconfig | grep “inet ” | grep -v 127.0.0.1 | cut -d\ -f2 Or for linux system hostname -i | awk ‘{print $3}’ # Ubuntu hostname -i # … Read more