Tag Info

Hot answers tagged

47

If you want the side-effects of the command list to affect your current shell, use {...} If you want to discard any side-effects, use (...) For example, I might use a subshell if I: want to alter $IFS for a few commands, but I don't want to alter $IFS globally for the current shell cd somewhere, but I don't want to change the $PWD for the current shell ...


20

To close CD tray with Ubuntu 11.04: eject -t or toggle with eject -T for a summary eject --help


11

From the official bash documentation: () ( list ) Placing a list of commands between parentheses causes a subshell environment to be created, and each of the commands in list to be executed in that subshell. Since the list is executed in a subshell, variable assignments do not remain in effect after the subshell completes. {} ...


7

Using the "raw output" mode of sensors for easier scripting: -u Raw output. This mode is suitable for debugging and for post- processing of the output by scripts. It is also useful when writing a configuration file because it shows the raw input names which must be referenced in the configuration file. For example: $ ...


6

Code in '{}' is executed in the current thread/process/environment and changes are preserved. Code in '()' is run inside a separate, child process of bash that is discarded after execution. This child process is often referred to as a sub-shell.


4

This script terminates the terminal and thus the shell and himself. It mercilessly kills all processes. If you have multiple tabs open in a terminal, then these are also closed. The problem is, if several terminals are opened and these are child processes of gnome-terminal-server, all terminals will be killed. In this case, the script should be started ...


4

All what you need is the power of awk and a for Statement: paste <(awk -F, '{ for (i = 29; i <= 188; i++) print $i }' PreRefFile.csv) <(awk -F, '{ for (i = 29; i <= 188; i++) print $i }' Txlog.csv) My test case: paste <(awk -F, '{ for (i = 2; i <= 3; i++) print $i }' foo1) <(awk -F, '{ for (i = 2; i <= 3; i++) print $i }' foo2) ...


3

The variable you set x="\$$y" is not available in the subshells <(...). Thats the problem. Use export to make it available in subsequently executed commands, but it will anyway be expanded by the parent shell. The subshells never see the variable, but instead see the value the parent shell substituted for it. As @EliahKagan noticed in the comments. Also ...


3

If you're opening just one file, you don't really need to use a script, because a script is meant to be an easy way to run multiple commands in a row, while here you just need to run two commands (including exit). If you want to run exit after a command or after a chain of commands, you can chain it to what you have already by using the && operator ...


3

(...) are used to run code in a sub-shell. Code used bewteen {...} won't be used in a sub-shell.


3

You don't actually have to include your password in your script (from what I have seen its generally not advisable to have your password in a script). Instead you can edit your sudoer file to allow you to run the apt-get command without the need for a password. For more information go to this website. open a terminal (ctrl + alt + T) Enter the command ...


3

Looks like a bug in the ubuntu-terminal-app. The bug description mentions a workaround: It seems to work when I use bash ./testscript. The ./ is optional


3

You can do this using xdotool. To install xdotool you can run: sudo apt-get update && sudo apt-get install xdotool Then to send a Ctrl+Alt+<keypad_key> keystroke to the terminal X window you can run: xdotool key Ctrl+Alt+<keypad_key_value> *<keypad_key_value> = keypad key's value in the list below To run a GUI program and ...


3

What you will run into If you want to first call an application and, subsequently, place its window on a specific position and size, the time between calling the application and the moment the window actually appears, is unpredictable. If your system is occupied, it can be significantly longer than if it is idle. You need a "smart" way to make sure the ...


3

I was too quick on this one, your test works. I suspect you somehow have set $SCREEN_NAME either globally or previously in the script as a string containing an illegal character. ^[a-zA-Z0-9_.-]+$ matches a non-NULL string containing only the allowed characters, so if $SCREEN_NAME is a non-NULL string containing only the allowed characters, $SCREEN_NAME =~ ...


3

I'm taking a guess that this is possibly you hitting an issue where stdout on a pipe buffers at 4K. See http://unix.stackexchange.com/a/25378 for some ideas on fixing it. To confirm this is your specific issue, try changing the name of your dummy file to something much larger, or call touch/rm multiple times, to generate enough output to hit the default ...


3

Since your real goal seems to be to automate whatever needs to be done to run your program, I suggest a different approach. Instead of writing a shell script, you can use a makefile. If you like, you can write a rule in your makefile for running your executable once it is built. You will then have two files--your C++ source code file and your makefile--and ...


3

If you're looking for a system command that always returns a non-zero exit code, then /bin/false seems like it should work for you. From man false: NAME false - do nothing, unsuccessfully SYNOPSIS false [ignored command line arguments] false OPTION DESCRIPTION Exit with a status code indicating failure.


2

You could do something like sensors -A | grep -oP '^Core.+? \+\K\d+' | awk '{k+=$1}END{print k/NR}' The grep will print only the relevant numbers (the spaces ensure that only the actual temperature is printed, not the critical or anything else) and the awk does the calculation. NR is the number of lines so that will work if the number of cores changes.


2

I have found the answer, just \[$(COMMAND) to run a command with every terminal prompt. For me i just put the command in a script and then run it by putting \[$(~/sound2.sh \# \u) at the end of the ps1 variable and before the ending ` of it --> in the .bashrc file And the script is: if [ $1 = 1 ]; then spd-say "Welcome $2" & else mplayer ...


2

Let's examine an example. File relative_urls.list: > cat relative_urls.list /users/449/oli /users/449 /help/badges /help/badges/185/curious /unanswered /questions/tagged/12.04 /questions/tagged/boot /questions/tagged/oracle /questions/tagged/internet_explorer /questions/tagged/outlook We'd like to check if these documents available on the site ...


2

Try this: #! /bin/bash sleep 2 while feh --cycle-once -zD $1 *.png; do :; done This way, the cycle will end when feh exits with a nonzero status (as it does when you terminate it).


2

Whatever it is (a bug or a weird configuration): ./yourscript.sh does not work on Ubuntu-touch. The workaround is: bash yourscript.sh


2

Awk compares floating point numbers. I just wrote a new script.: paste <(awk -F, '{print $29}' file1 ) <(awk -F, '{print $29}' file2 ) | awk '{print $1; print $2; print ($1==$2)?"match" :"mismatch"}' If you do not like breaks, then use printf instead of print. Example: File1: ...


2

You can create a new return code with the command bash -c "exit RETURNCODE", replacing "RETURNCODE" with any number. Note that it will be trimmed to an 8bit unsigned integer (0...255) by (RETURNCODE mod 256) You can check the return code of the last shell command inside the terminal(!) with executing echo $?. The "$?" variable contains the most recent ...


2

Using bash: #!/bin/bash paste PreRefFile.csv Txlog.csv | while IFS=$'\t' read a b; do i=29 while [[ $i -le 189 ]]; do printf "$(cut -d, -f$i<<<"$a")\t$(cut -d, -f$i<<<"$b")\n" i=$((i+1)) done done Using python: #!/usr/bin/env python2 import csv, itertools with open('PreRefFile.csv') as a, open('PreRefFile.csv') as b: ...


1

The simplest solution would be: xdg-open file.pdf && exit Unlike other similar command nohup is not needed to make the command ignoring SIGHUP, the reason being xdg-open will exit spawning a child process which is preferred application to open the pdf file. As the actual process started from the terminal is no longer there to be killed, nohup is ...


1

The actual command you want is something like wmctrl -r :ACTIVE: -b add,maximized_vert && wmctrl -r :ACTIVE: -e 0,0,0,$HALF,-1 That will make the current window take up half the screen (change $HALF to the dimensions of your screen) and snap to the left hand side. To snap to the right, use wmctrl -r :ACTIVE: -b add,maximized_vert && ...


1

Trap the INT signal, eg: Ctrl+C more infos here trap trapint 2 function trapint { exit 0 } In your code like this: #!/bin/bash trap trapint 2 function trapint { exit 0 } sleep 2 while true; do feh --cycle-once -zD $1 *.png done


1

It would be better to use your backups, if you have them. If not, you can use find to delete the files: find /path/to/site/folder -type f -iname 'index.php' -delete This deletes regular files (-type f, so not directories) named index.php (ignoring case).



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