Hot answers tagged

6

Here's a more "bashy" and concise approach: #!/bin/bash ## Read the UUIDs into the array 'uuids'. Using awk ## lets us both skip comments and only keep the UUID mapfile -t uuids < <(awk '!/^\s*#/{print $1}' uuids.txt) ## Iterate over each UUID for uuid in ${uuids[@]}; do ## Set the special array $_ (the positional parameters: $1, $2 etc) ...


5

Walk over the files, create an associative array over the uuids contained in their names (I used parameter expansion to extract the uuid). The, read the list, check the associative array for each uuid and report whether the file was recorded or not. #!/bin/bash uuid_list=... declare -A file_for for file in *_*_* ; do uuid=${file%%_*} ...


5

This is pure Bash (i.e. no external commands), and it's the most coincise approach that I can think of. But performance-wise is really not much better than what you currently have. It will read each line from path/to/file; for each line, it will store the first field in $uuid and prints a message if a file matching the pattern path/to/directory/$uuid* is ...


4

You have a few issues in your setup: one will definitely make it not work, the other most likely: 1. The most important one: In the .desktop file, you use: Exec=~/.config/autostart/unity_dash_update.sh but ~ does not work ina a .desktop file, you need to use absolute path, unless your script is in $PATH (and executable), then simply run it by its name. ...


4

Using shutter and wmctrl, an edited version of this script does pretty much exactly what you describe: it takes a screenshot of the area, a specific window covers on your screen, no matter if and how the window is (partially) below other windows. The marge around the window, to be included in the screenshot, is arbitrary; set it to zero if you like. In ...


3

dbus actually has a method for closing the Dash menu. Using qdbus your script could be changed as follows: #!/bin/bash DISPLAY=:0 sleep 10 xdotool key Alt+F2 sleep 0.25 qdbus com.canonical.Unity /com/canonical/Unity/Dash \ com.canonical.Unity.Dash.HideDash exit 0 Note that in addition i've increased sleep time to 10 seconds, because Unity may take ...


2

Perhaps the easiest way to do this is to place your script in $HOME/bin and making sure that the permissions are set to executable: chmod +x $HOME/bin/script.py Now you should be able to run the script from any directory.... A couple of other points to be aware of: Ensure that $HOME/bin is in your $PATH, for Ubuntu this will be set by default in ...


2

Put this line in your .bashrc assuming you're using bash as shell: export PATH=/path/to/your/script/:"$PATH" You can use vi, nano or gedit to edit this line in the end of the file. Make sure your script is set to executable mode, if it's a bash script: chmod +x script.sh Or if it's a Python script: chmod +x script.py On your script indicate their ...


2

You can check if the parent process is the shell. For example: #! /bin/bash if [[ $(readlink -f /proc/$(ps -o ppid:1= -p $$)/exe) != $(readlink -f "$SHELL") ]] then echo "Starting the shell..." exec "$SHELL" else echo "Not starting a shell." fi ps -o ppid:1= -p $$ prints the PID of the parent process (ppid) of the current process (-p $$). A ...


2

Might be ubuntu-mate startup program taking time to load(touchpad driver). you can try adding sleep into your above script. #!/bin/bash sleep 30 xinput set-prop 10 "Device Enabled" 0 exit 0 Please increase the sleep time if above does not work.


2

Open Nautilus, Top menu, Edit -> Preferences -> Behaviour Change View executable text files when they are opened to either Run executable text files when they are opened (warning: Potentially dangerous!) or Ask each time


2

You have changed the value of conditional variable (copystat) outside the while loop (running in a subshell), which is outside the scope of the while loop. Unless you have some condition inside the loop itself to trigger the loop exit condition or use an IPC, the loop will continue forever. So the solution is to incorporate the copying or any other ...


2

The problem you have is caused by the subshell spawned when you call transprog to run in the background (what the & symbol does). You have to understand that your bash script is not a program but a shell script which behaves according to the shell rules - a shell can only run one process at a time and wait for it to terminate. The "jobs system" allows ...


2

unset IFS set -f set +f -- $(<uuid_file) while [ "${1+:}" ] do : < "$source_directory/$1"* && printf 'File for %s has arrived.\n' "$2" shift 2 done The idea here is not to worry about reporting errors the shell will report for you. If you try to < open a file which doesn't exist your shell will complain. In fact, it ...


1

The at command doesn't need to be given an absolute path if you are running it from the same location. If you are running it from the same location where you have your script just give the script's name.


1

The way I'd approach it is to get uuids from file first, then use find awk '{print $1}' listfile.txt | while read fileName;do find /etc -name "$fileName*" -printf "%p FOUND\n" 2> /dev/null;done For readabilty, awk '{print $1}' listfile.txt | \ while read fileName;do \ find /etc -name "$fileName*" -printf "%p FOUND\n" 2> /dev/null; ...


1

You must add then after square brackets because then IF will know that IF $runNumber -eq 1 he will do that. So correct script should look like: if [ $runNumber -eq 1 ]; then cp constant/polyMesh/blockMeshDict ./ rm -rf constant/polyMesh/* mv ./blockMeshDict constant/polyMesh blockMesh > log.blockMesh 2>&1 decomposePar -cellDist ...


1

An if statement in bash looks like this (indentation is optional): if [ CONDITION ] then COMMAND1 MORE_COMMANDS else COMMAND2 MORE_COMMANDS fi Or in one line: if [ CONDITION ] ; then COMMAND1 ; MORE_COMMANDS ; else COMMAND2 ; MORE_COMMANDS ; fi It is important that if and then are two separate commands (separate lines or separated ...


1

Use import with the -screen option, like import -screen -window 'id' test.png


1

I checked the differences between the environment when running a script from the terminal and the environment when running a script by double-clicking it in Files; When you run a script by double clicking in Files the $VTE_VERSION variable is unset, so you can hook to it to decide whether to replace the current Bash instance with an interactive one or not. ...


1

Options to prevent an application to run while VPN is running There are several options to prevent running an application when VPN is running: Combine the command to open VPN with the command to kill the application Run a small background script to kill the application if VPN runs Although the first option seems to be the cleanest, there are a few ...



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