sh

How to invoke octave script in unix shell

青春壹個敷衍的年華 提交于 2019-11-30 19:34:23
问题 I have written an octave script file (.m) If anyone could point me out on how to run octave scripts on unix shell that would be really helpful. I do not want to execute the script by invoking octave program. I am new to unix and octave. Thanks in advance 回答1: Yes, of course you can write an Octave program. Like so: $ cat octave_program #!/usr/bin/env octave ## Never forget your licence at the top of the files. 1; function [rv] = main (argv) disp ("hello world"); rv = 0; return; endfunction

can't source script in a current directory

元气小坏坏 提交于 2019-11-30 19:13:28
So apparently, I can't source a script if that script is in the current directory. For example, # source some/dir/script.sh Ok works fine, but if I'm in the same dir as the script, it errors out: # cd some/dir # source script.sh -sh: source: script.sh: file not found What gives? Is the only way around this to change directory? I'm using bash v4.2.10 on Angstrom Linux if that's relevant. Quoting the source man page: source filename [arguments] .... If filename does not contain a slash, file names in PATH are used to find the directory containing file- name. So... source is trying to search your

What is the use of “echo || true”?

ⅰ亾dé卋堺 提交于 2019-11-30 18:54:40
Why would anyone want to have a code like echo "something" || true ? I found such a usage on line 92 of /lib/lsb/init-functions on an Ubuntu 14.04: echo "$pid" || true I understand that || stands for OR. But I could not find a way to make echo produce any sort of exit code other than zero. And even if it does, who cares? I mean, using the prefix || true ensures that the exit code is always 0. So if the left-hand side of the double pipe yields anything different from 0, true will be executed and cause the whole line to yield 0. Why the paranoia with the exit code of a simple echo? Is there

How to check if two paths are equal in Bash?

无人久伴 提交于 2019-11-30 17:16:26
What's the best way to check if two paths are equal in Bash? For example, given the directory structure ~/ Desktop/ Downloads/ (symlink to ~/Downloads) Downloads/ photo.png and assuming that the current directory is the home directory, all of the following would be equivalent: ./ and ~ ~/Desktop and /home/you/Desktop ./Downloads and ~/Desktop/Downloads ./Downloads/photo.png and ~/Downloads/photo.png Is there a native Bash way to do this? Bash's test commands have a -ef operator for this purpose if [[ ./ -ef ~ ]]; then ... if [[ ~/Desktop -ef /home/you/Desktop ]]; then ... etc... $ help test |

Capturing the PID of a background process started by a Makefile

▼魔方 西西 提交于 2019-11-30 14:04:54
I have a Makefile that starts a Django web server. I would like the server to be started in the background, with the PID saved to a file. My recipe looks like this: run: venv @"${PYTHON}" "${APP}/manage.py" runserver 80 Intuitively, to background the process and capture the PID, I'd have to do something like this: run: venv @"${PYTHON}" "${APP}/manage.py" runserver 80 & ; echo "$$!" > "${LOGDIR}/django.pid" This doesn't work, though. The sub-shell that 'make' uses (/bin/sh in my case) works when you use: <command> & ...to background a process, and works when use: <command> ; <command> (or

getting error /usr/bin/env: sh: No such file or directory when running command play

£可爱£侵袭症+ 提交于 2019-11-30 13:11:01
问题 I am a beginner on Play framework . I just extract Play framework files and extracted them and gave the path of play directory in $PATH global variable. After this when I run the the command on ubuntu play help, its giving me below error: /usr/bin/env: sh: No such file or directory Any clue why I am facing this error and how to resolve it ? 回答1: This error usually happens if the script has windows line endings instead of unix line endings. Try running dos2unix on the script and try running

bash: Delete all files older than 1 month, but leave files from Mondays

帅比萌擦擦* 提交于 2019-11-30 12:49:25
I have a lot of daily backup archives. To manage disk usage, I need a bash script that will delete all files older than 1 month, but keep all files created on Mondays, even if they are older than 1 month. For example, this will delete all files last modified more than 30 days ago: find /path/to/files* -type f -mtime +30 -delete But I don't really know how to keep files created on Mondays. Slightly simpler and more cautious version of @JoSo's answer: find /path/to/files -type f -mtime +30 \ -exec sh -c 'test $(date +%a -r "$1") = Mon || echo rm "$1"' -- {} \; The differences: Using date -r to

How to tell if any command in bash script failed (non-zero exit status)

跟風遠走 提交于 2019-11-30 12:24:08
I want to know whether any commands in a bash script exited with a non-zero status. I want something similar to set -e functionality, except that I don't want it to exit when a command exits with a non-zero status. I want it to run the whole script, and then I want to know that either: a) all commands exited with exit status 0 -or- b) one or more commands exited with a non-zero status e.g., given the following: #!/bin/bash command1 # exits with status 1 command2 # exits with status 0 command3 # exits with status 0 I want all three commands to run. After running the script, I want an indication

Shell read *sometimes* strips trailing delimiter

大憨熊 提交于 2019-11-30 12:00:06
To parse colon-delimited fields I can use read with a custom IFS : $ echo 'foo.c:41:switch (color) {' | { IFS=: read file line text && echo "$file | $line | $text"; } foo.c | 41 | switch (color) { If the last field contains colons, no problem, the colons are retained. $ echo 'foo.c:42:case RED: //alert' | { IFS=: read file line text && echo "$file | $line | $text"; } foo.c | 42 | case RED: //alert A trailing delimiter is also retained... $ echo 'foo.c:42:case RED: //alert:' | { IFS=: read file line text && echo "$file | $line | $text"; } foo.c | 42 | case RED: //alert: ...Unless it's the only

Adding users to sudoers through shell script

喜你入骨 提交于 2019-11-30 11:52:04
问题 Is it possible to add users to the sudoers file through a shell script? I've been looking around, still can't find anything. 回答1: You could simply echo (with elevated privileges, of course) directly to the /etc/sudoers file: sudo -i echo 'nickw444 ALL=(ALL:ALL) ALL' >> /etc/sudoers # ^^ # tab (note the tab character between the username and the first ALL ) Or, for a script: #!/bin/bash # Run me with superuser privileges echo 'nickw444 ALL=(ALL:ALL) ALL' >> /etc/sudoers Then save to somefile