Hot answers tagged

5

The basic control structure in any sort of programming language that requires indefinite looping is while loop. while true ; do /path/to/script.sh ; if [ $? -ne 0 ] ; then continue ; else break ; fi ; done More readable formating would be : while true do /path/to/script.sh # Ensure your script actually outputs exit status if [ $? -ne 0 ] ; ...


4

You can first try to just copy the default .profile from the original copy found in /etc/skel/: /bin/cp /etc/skel/.profile /home/<username>/ If for some reason that does not work, you can follow the next part to replace your .profile from its original contents: Boot your system to Recovery Mode first so that you have root capabilities to your ...


4

With bash, in an arithmetic evaluation context, variable names do not require the $ prefix. That means this is possible: # set up the variables hat=1 shirt=2 trousers=4 string="my_outfit=shirt+trousers" # evaluate the equation (( $string )) echo $my_outfit outputs 6


4

You appear to have configured readline to enable edit mode indication. From 8.3.1 Readline Init File Syntax of the Bash Reference Manual: show-mode-in-prompt (Off) If set to On, add a character to the beginning of the prompt indicating the editing mode: emacs (@), vi command (:) or vi insertion (+). You should be able to ...


3

If you replace the command: xset dpms force standby that you currently use in the shortcut, by the command: /bin/bash -c "sleep 2 && xset dpms force standby" It will work exactly as you describe.


3

folder is now located in the parent of the parent (../..) of the directory that was the current directory at time the mv command was executed. If your intention was to move folder into /var you should have done: mv /var/www/folder/ /var/www/folder/../../ Or simply mv /var/www/folder/ /var/ To display current directory use pwd, for example $ pwd ...


3

Run them as: /path/to/script.sh && /path/to/script.sh The second one will run if the first one succeeds. Without depending on the success of the first one: /path/to/script.sh; /path/to/script.sh Run second one only if the first one fails: /path/to/script.sh || /path/to/script.sh For real cyclic execution, you can use a recursive function: ...


2

Use: timedatectl status | grep "Time zone" Without the grep you get a lot more of information.


2

First you need to make sure each line/part of your bash script work in a shell (outside of a script). I cannot tell if yours will so you'll have to check that yourself. And to execute a python script you need python BEFORE the path to the script Also: ~ is a shortcut to the home directory of the current user ~asdf is a shortcut to the home directory for ...


2

I assume the point is to transfer the content of magento to /var/www/html. That's to say, if we had: magento ├── .bar └── foo We'd get: html ├── .bar └── foo This is annoying, but not difficult, to accomplish this with mv. You'd have to use some form of find, or enable dotglob in bash, to include the .bar. rsync is simpler. With find: find magento ...


2

Probably not. Or, at least, it will be really complex. The problem here is that foo= is interpreted by bash as an attempt to set the variable foo to something. So, when you hit tab it tries to complete with the names of the files in the current directory. It isn't actually completing foo=, it is starting a whole new glob from nothing. Note that it takes two ...


2

The variable used is empty, leading to the error message regarding unary operator. Possible reason could be there is no rootfs in df -H output i.e. in your system. $ foo= $ [ $foo -gt 10 ] && echo OK bash: [: -gt: unary operator expected You have also some other issues in your script, the OR logic should be put as: [ "$foo" -gt "$bar" ] || [ ...


2

Why not just run the script as superuser? sudo sh recover.sh


2

You are searching for the task spooler command. In the Debian/Ubuntu's repositories, the pacakage to install is task-spooler and the binary to call is tsp. In your case (&& style) you could use tsp -d cmd1 tsp -d cmd2 tsp -d cmd3 then use tsp -l to inspect the status of the queue. There are ways (-S) to increase the number of max ...


2

To add a script to a keyboard shortcut: Unless the script is in $PATH (like ~/bin), use the full path to the script, don't use ~ or relative paths. If you use full path, start (as always) with a slash, e.g.: sh /home/username/script.sh Your example doesn't :) If your script is executable, just the full path will do: /home/username/script.sh if it ...


2

This is not a Linux thing, it's a bash thing. Bash is just one of many shells. Bash is the "Bourne again shell" and was released as a replacement of the original Bourne Shell, sh. POSIX is a set of standards defining how POSIX-compliant systems should work. The POSIX shell standard can be found here. Bash has many features not present in sh and is not ...


2

Here's a variant of your original method, but using bash arrays. Note that there's no need to save an restore the field separator - you can simply assign a temporary value when you read the string #!/bin/bash # create a map (lookup table) from items to values declare -A values=( [hat]=1 [shirt]=2 [trousers]=4 ) # (an ASSOCIATIVE array) ...


2

Just create a function: function masterScript() { if [ -e /home/arun/Desktop/scripts/myMasterScript.sh ] then bash /home/arun/Desktop/scripts/myMasterScript.sh fi } And make sure your script is executable: chmod 755 /home/arun/Desktop/scripts/myMasterScript.sh


1

I tried this out .. I simply made it alias masterScript="cd /home/arun/Desktop/scripts && myMasterScript.sh"


1

Shell parameter substitutions like ${string/pattern/replacement} don't modify the original value of string. You need to assign the result of each substitution back to the variable, e.g. vString="${vString/@@d/$vTipo}" vString="${vString/13/$vMes}" vString="${vString/1986/$vAno}" and so on.


1

I have just written and tested this and it works for me, assuming your text is in a file called: text_for_sed.txt command: sed -n "/<tmp>\([[:digit:]]\{2\}\)<\/tmp>/{ s/<tmp>\([[:digit:]]\{2\}\)<\/tmp>/\1/p n s/<flik>\([[:digit:]]\{2\}\)<\/flik>/\1/p n s/<t>\([[:alpha:]]\+\)<\/t>/\1/p }" ...


1

#!/bin/bash data=$(lynx -dump "http://wxdata.weather.com/wxdata/weather/local/14225?cc=*&unit=f&dayf=1" | grep -A 2 -m 1 "<tmp>") for pattern_to_find in tmp flik t do $data | tr " " "\n" | sed -ne "/<$pattern_to_find>/s#\s*<[^>]*>\s*##gp" done Explanation: $data | tr " " "\n" | sed -ne ...


1

Adding to @AndroidDev's answer, a script in Python: #!/usr/bin/env python import subprocess apps_to_save = ['Gedit', 'Writer'] battery_limit = 10 # in percent def get_battery_percentage(): percentage, err = subprocess.Popen([r'upower -i $(upower -e | grep BAT) | grep --color=never -E percentage | xargs | cut -d ' ' -f2 | sed s/%// '], shell=True, ...


1

You can use... echo password | sudo -S recover.sh Password being your sudo password. From sudo manpage.. -S, --stdin Write the prompt to the standard error and read the password from the standard input instead of using the terminal device.


1

The solution is that you are logged into the Bash shell as root. The beginning of the cursor line should say your username @ your computer name not root @ your computer name and the end of the cursor should have a $ not a #. The root account doesn't have a Downloads directory which is why you are getting the error. If this is the case you can type exit and ...


1

An easier way would be to put your startup commands in a script, and invoke that: # You could put the file in any other directory that is mounted # early in boot time (not your HOME directory) cat >>/var/local/foo <<EOF #!/bin/bash # Suggestion: use absolute path: /usr/local/bin/rtl_tcp rtl_tcp sleep 4 # Warning - MUST specify absolute path! ...


1

To make your script execute again and again you can do it like this (make sure th script has chmod 755 set): #!/bin/bash echo "test" #or whatever you do in your script exec sh <scriptname> You can stop your script ctrl+c. Note that the use of exec means that there will be at most one process running at a time, instead of having a new process added ...



Only top voted, non community-wiki answers of a minimum length are eligible