New answers tagged

1

The difference between running the script via systemd and running it directly it directly is the environment. You can test it like this. In your Unit file, add this to the [Service] section, for testing: StandardOutput=console Then in your bash script, at the top add this line to dump the environment: env Now run the script inside and outside of ...


0

I was taking the wrong approach. The easy (but ugly) way to do this is to modify the SConstruct file so that there is some trigger that will modify the environment programmatically before the Shell is invoked. For a proof of concept, I've used my username as the trigger: import getpass and later on msvcEnv = MSVCCompiler.CreateEnvironment(baseEnv) ...


0

I'm not sure if I understood what you need. Please tell me if the following code doesn't solve your problem. # !/bin/bash echo "Please enter a number." read NUM while read -n1 DIGIT; do echo "Digit: $DIGIT" while true; do RND=$((RANDOM%10)) if [[ "$RND" == "$DIGIT" ]]; then echo "$RND matches."; break; ...


1

This is controled by a zstyle: zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}' This tells zsh that small letters will match small and capital letters. (i.e. capital letters match only capital letters.) If you want that capital letters also match small letters use instead: zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' If you want ...


1

Binding ctrl+enter doesn't make any sense. The enter key normally sends a carriage-return; \r, aka \cM. In other words, enter is already a control character. So applying the \c modifier does’t make any sense. In fact, this should cause Fish to generate an error so I’ll open an issue to remind the team to fix that. Also, you were trying to bind \c\n. Binding ...


0

This doesn't need a 'coded solution.' If you sort the lines first, the algorithmic complexity is reduced by several orders of magnitude. See this answer for better performance, both in terms of CPU time and memory: https://stackoverflow.com/questions/4366533/remove-lines-from-file-which-appear-in-another-file


1

If your variables are all exported in the same way (export foo=bar), then you can source all of them easily using bash process substitution feature: source <(grep '^export .*=' file1.sh) Man page extract: Process Substitution Process substitution is supported on systems that support named pipes (FIFOs) or the /dev/fd method of naming ...


0

There are three options I use when I have a bash script that I want to behave differently when it is sourced vs. when it is executed (or in other words have data items in a script that I want access to without executing any code at that time). The comments touched on them to an extent. Option One Determine when being sourced and end 'sourcing' at ...


0

This trick works for me in times of desperation. YMMV rename \- '' * You have to escape the hyphen for rename to recognize it. Why rename doesn't respect single quotes or offer an override of some kind is beyond me. This is the only method I've seen that reliably handles a leading hyphen using rename. I agree with the other posts on using mv, but if you ...


0

It looks as if it ran asynchronously while in fact it did not. When firefox launches it checks for existing instance, if found it delegates control to existing instance and ends itself. Hence the confusion.


1

I actually looked pretty hard for this after both a full install and a brew cask install of libreoffice gave the same error. I found the answer in a comment on Github. Seems libreoffice gives this Info.plist error in calling soffice via a symlink. Calling soffice directly via /Applications/LibreOffice.app/Contents/MacOS/soffice or by making a small shell ...


3

You didn't specify an operating system. This answer assumes Windows. My first thought was a simple command such as for %f in (*.png) do rename "%f" "New_%f" But a file named a.png was first renamed to New_a.png and moved down the alphabetical order :-( The loop renamed this file a second time to New_New_a.png. Therefore, this must be done in two steps: ...


1

Copied from my answer on Stack Overflow: Instead of creating a passwd file, which Cygwin recommends against1, you could edit /etc/nsswitch.conf. Add or edit the following line: db_shell: /usr/bin/zsh The down/up side of this method is that, if you have multiple users, this change affects all of them. The up/up side is that it's dead simple. The ...


0

Copied from my answer on Stack Overflow: Instead of creating a passwd file, which Cygwin recommends against1, you could edit /etc/nsswitch.conf. Add or edit the following line: db_shell: /usr/bin/fish The down/up side of this method is that, if you have multiple users, this change affects all of them. The up/up side is that it's dead simple. The ...


1

Do this :This is for cross fade with two videos ffmpeg -i big_buck.mp4 -i big_buck.mp4 -an -filter_complex " [0:v]trim=start=0:end=4,setpts=PTS-STARTPTS[firstclip]; [1:v]trim=start=1,setpts=PTS-STARTPTS[secondclip]; [0:v]trim=start=4:end=5,setpts=PTS-STARTPTS[fadeoutsrc]; [1:v]trim=start=0:end=1,setpts=PTS-STARTPTS[fadeinsrc]; [fadeinsrc]format=...


0

I have come up with a Bash script that should work to make this happen. # Automatically do an ls after each cd cd() { if [ -n "$1" ]; then builtin cd "$@" && ls --group-directories-first else builtin cd ~ && ls --group-directories-first fi }


0

The GNU utility expand does not provide the 'in place' update that sed does. It's fairly trivial to reproduce the same result, although the command may be slighter longer. It isn't possible to parse and update a file simultaneously on an arbitrary file system without risking corruption, and for that reason and others sed doesn't actual do it, although it ...


0

You must also set eshell-prompt-regexp to match what eshell-prompt-function returns or you'll have problems like Palace Chan in the comment above this.


0

You could do it in awk. Put the following script in a file and then call awk -v pattern=disk60 -f script_file data_file: found { buf = buf "\n" $0 } /multipath *\{/ { buf = $0; found = 1 } $0 ~ pattern { matched = 1 } /\}/ { if (matched) { gsub(/\n/, "\n#", buf); buf = "#" buf; } print buf "\n"; found = matched = 0; } This ...


2

Create a new file containing the content as you wish it. For your situation, this can be done like this: echo "[" > database-new.json ; cat database.json >> database-new.json ; echo "]" >> database-new.json > is create new file (clearing the file if existing) and direct stdout to it. >> is append stdout to file.


0

You can do so by using: #!/bin/bash mount /dev/<device> /foo exit 0 #!/bin/bash is the required shebang, mount /dev/<device> /foo is the command and parameters, exit 0 exits cleanly Change /dev/<device> and /foo to your desired paths, and /bin/bash to the shell you use. Also remember to chmod +x your script to make it executable


0

loffice is the command you are looking for. Here is a snippet from the output I got after running loffice --help --convert-to output_file_extension[:output_filter_name[:output_filter_options]] [--outdir output_dir] files Batch convert files (implies --headless). If --outdir is not specified then current working dir is used as output_dir. Eg. --...


0

You need to place the commands you want run by "user" in a script, then run the script using sudo, which you should use instead of su. For example: myFunction() { user="$1" tmpfile=$(mktemp) echo "date" >> $tmpfile # ... put other stuff in tmpfile sudo -u $user $tmpfile rm $tmpfile }


1

Another way to do this in awk without grep: df -hT /home/user | awk '$1 ~ "sda1"{gsub(/[A-Z]/,"",$4); print $4}' The test on the front of the awk block $1~"sda1" is just checking to see that your main hard drive is the one that df is looking at. This is a lot safer than grabbing df records that don't contain filesystem which may spit out more than just ...


1

Use $2+0 to make it a number in awk. You don't need grep as you can perform search in awk itself. You can use: df -hT / | awk '/^Filesystem/{ print ($2+0) * 15/100 }'


0

anc is designed to do stuff like this as well. https://github.com/tobimensch/anc Here's an excerpt from the README: # make the current directory the default anchor: $ anc s # go to /etc, then /, then /usr/local and then back to the default anchor: $ cd /etc; cd ..; cd usr/local; anc # go back to /usr/local : $ anc b # add another anchor: $ anc a $HOME/...


0

Seacrhing more sources, I think I found the answer. Although the editor did exist up to Windows XP File Types window > Advanced button > Actions button it seems no longer to be part of the Windows user interface. The only possibilities seem to use either the registry (complete reference) or some 3rd party editors.


2

We can place validation at the beginning of script. userid=`id -u -n` #echo "$userid" ; ownuser=`ls -l ${abosolutepath}/${your_script.sh} | awk '{print $3}'` #echo "$ownuser" ; if [ ! "$userid" = "$ownuser" ]; then echo permission denied exit 1 fi Above validation will check if the user who executing this script is same as user who own ...


0

If you have scripts lying around that you need to run often, and they depend on their location for finding resources you can easily do this by just combining commands in an alias like this. alias run-script="cd /home/user/path/to/script/ && bash script.sh" This way you don't have to alter anything else to make it work.


2

In general, this is not possible. Any user who is able to execute a shell is also able to execute any shell script they can read. The shell does not really distinguish between commands that come from the terminal and commands that come from a file. So you would probably need some kind of restricted "shell". In principle, any program can be used as a login ...


2

Without involving ACL or SELinux the only way I find is adding at the beginning of the script this: if [ "$USER" = "ronly" ]; then echo 'Access denied' exit 1 fi This is far from perfect because: The user ronly can read the script, so he can copy the contents to a script in his own home and execute it. Any user can freely set their $USER environment ...



Top 50 recent answers are included