Tag Info

Hot answers tagged

17

If your shell supports process substitution, try: diff <(head -n 1 filea) <(head -n 1 fileb)


11

Because the way you define it py is a shell alias, and Vim doesn't know (nor care) about shell aliases. Use an environment variable instead, perhaps like this: $ PY=/opt/python3.4/bin/python3 $ export PY then in Vim: ... exec '!time ' . fnameescape($PY) . ' %' ... Edit: Added fnameescape(). It's needed if $PY contains characters that have a special ...


10

You can use a "here-document" with the - modifier. It can be indented by tab characters. You must switch from echo to cat. cat <<-EOF > /etc/apache/sites-availabe/000-default.conf <VirtualHost *:80> redirect 404 / ErrorDocument 404 </VirtualHost> EOF Or, to keep tabs in the result, you can ...


9

The "Network is not reachable" message is printed to stderr, not stdout, so it isn't captured by your substitution ($(ping ...)). You need to redirect stderr to stdout when running ping, not when you log: print_and_log "$(ping -c10 "$i" 2>&1)"


7

A few approaches: printf '%s\n' > "$conf_file" \ '<VirtualHost *:80>' \ ' redirect 404 /' \ ' ErrorDocument 404' \ '</VirtualHost>' If you want escape sequences to be expanded replace %s with %b: printf '%b\n' > "$conf_file" \ '<VirtualHost *:80>' \ '\tredirect 404 /' \ '\tErrorDocument 404' \ ...


6

You're confusing bash with csh. In bash like in any Bourne-like shell, set is the command to set options (shell configuration settings like -f, -C, -o noclobber...) and positional parameters ($1, $2...). set FILEM="razrax" Sets $1 to FILEM=razrax. $ set FILEM="razrax" $ echo "$1" FILEM=razrax The syntax for variable assignment in Bourne-like shells ...


6

If you are only comparing the first line of each file, maybe you care about word-level changes within the line, using dwdiff: dwdiff <(head -n 1 filea) <(head -n 1 fileb) dwdiff has some nice options, like -c to colorize the changed words. Or, using sed instead of head: dwdiff <(sed 1q filea) <(sed 1q fileb) which the manual for head ...


6

You could use the timeout command : if timeout 10 ping google.fr > /dev/null then echo "process successful" else echo "process killed" fi shows process killed, and if timeout 10 ls /usr/bin | wc -l > /dev/null then echo "process successful" else echo "process killed" fi shows process successful. Based on this, you could run each ...


5

You are mixing shell and sqlplus commands. sqlplus doesn't understand redirections, you have to use the spool keyword. For instance: SQL> spool /tmp/result.txt SQL> start requete.sql SQL> spool off From shell: $ sqlplus scott/tiger @requete.sql > /tmp/result.txt


5

Let us define foo: $ foo="*" Now, try echo without quotes: $ echo $foo File1 File2 The replacement of * with a list of filenames is called pathname expansion. It can be suppressed with with double-quotes: $ echo "$foo" * In addition, double-quotes will prevent brace expansion, tilde expansion, and word splitting. For completeness, try echo with ...


5

As @lcd047 told you, aliases are not available to vim. They are also, by the way, not available to shell scripts either, unless you activate the expand_aliases option. Anyway, another choice would be to create a link instead of an alias: sudo ln -s /opt/python3.4/bin/python3 /usr/bin/py That will create a link at /usr/bin/py which points to ...


5

You can just use a negative index ${myarray[-1]} to get the last element. You can do the same thing for the second-last, and so on; in Bash: If the subscript used to reference an element of an indexed array evaluates to a number less than zero, it is interpreted as relative to one greater than the maximum index of the array, so negative indices ...


4

That key/schema was removed in gnome-shell ≥ 3.10 so the solutions you found on the internet no longer work. Ray Strode, gnome dev1: I've had a couple of people ask me if there's a way to do this in gnome-shell 3.10 and later and I haven't had a good answer. It's complicated by the fact that g-s-d now handles starting things and the ...


4

Two application types come to my mind where shell loops are not considered to be the best approach. The first is data processing; many tools (like sed, awk, perl, etc.) do the loop implicitly and much more performant. The second is (like in your sample code), where some code is executed for a set of files, where find with the -exec switch can also already ...


3

Everything what you need to loop through acids in File1.txt and find matched line in File2.txt + 1 line which easy done by grep for acid in $(sed 's/^\s*//' File1.txt) do grep -FA1 "$acid" File2.txt done > Output.txt But if you like awk: awk ' FNR!=NR{ print " [",$1,"]" print acids[$1] next } /\[/{ acid=$2 next } { ...


3

This is more a "terminal application" feature/configuration option than a bash option. Bash is not aware of fonts or spaces, that's something related to the terminal. For example: Mac Os X's terminal program allows to setup more space between the lines: http://osxdaily.com/2015/01/05/increase-line-spacing-terminal-mac-os-x/ If that's what you're looking ...


3

You may use this: num=5; echo $(seq $num) Gives: 1 2 3 4 5 Remark: $(...) syntax is command substitution.


3

If your tty has the noflsh flag turned off - you can check with stty -a < /dev/pts/whatever | grep -e -noflsh from another tty, but the default is that it's turned off - then typing the interrupt, quit, or suspend character will flush the input queue. So if you type Ctrl-Z, then fg, it will suspend the currently running command, flush the input, then ...


3

You can certainly kill the child process after some execution time and append the text file you need with '0' from within your bash-script. You may find Bash script that kills a child process after a given timeout useful.


3

Check out type ll to see :) On Fedora you're likely to get something like ll is an alias for ls -l, which would mean that Fedora just comes preconfigured with the same alias you've mentioned.


2

Based on don_crissti answer, I have created a bash script for automating this task. Here is the script: #!/bin/bash if [ -z $1 ]; then echo "usage: screencast <outfile>" exit 1 fi fname=$1 audio=$(pacmd list-sources | sed -n 's/\s*name: <\(.*\.monitor\)>/\1/p') pacmd set-default-source "$audio" echo "Screencast started, to stop it ...


2

dd if=boot1h of="/dev/r$temp1" status=none The status= flag controls which info to suppress outputting to stderr; 'noxfer' suppresses transfer stats, 'none' suppresses all dd (coreutils) 8.21


2

The bash process that keeps running is the parent of tee, not the original script. You can see that by adding traces that display the process IDs: #!/bin/bash echo original=$$ exec > >(echo substitution=$BASHPID; tee /tmp/mylog.log) 2>&1 bash -c 'echo sleeper=$$; sleep 12312' & This makes an additional bash process appear, the parent of ...


2

Yuch, too much maintenance and too much individual stuff. I'd recommend putting most of the effort into having appropriately scoped names that are appropriate for the platform so you can just have all of them all of the time. PYTHONPATH is a good example... you're unlikely to want to repurpose it for a Ruby project... You can group and mark the group with ...


2

The --radiolist needs two variables, not one. As explained in man dialog: --radiolist text height width list-height [ tag item status ] ... A radiolist box is similar to a menu box. The only difference is that you can indicate which entry is currently selected, by setting its status to on. As you can see above, it needs both tag and ...


2

The instructions you cited said to do this: wget http://www.eng.lsu.edu/mirrors/apache/maven/maven-3/3.2.3/binaries/apache-maven-3.2.3-bin.zip unzip apache-maven-3.2.3-bin.zip mv apache-maven-3.2.3/ /opt/maven This will result in /opt/maven/bin, /opt/maven/lib, etc. What you did was slightly different: wget ...


2

With xargs/grep: xargs -n1 -I '{}' grep '{}' -A1 File2.txt <File1.txt Explanation: -n1: forces xargs to execute the command for every line -I '{}': set a placeholer grep '{}' -A1 File2.txt: the command to execute -A1: print also the line after the search pattern File2.txt: search trough File2.txt <File1.txt: input is File1.txt


2

A quick way to do this is using: while read amino_acid do grep -A1 ${amino_acid} File2.txt >> output.txt done < File1.txt


2

If you know that the date format will always have six space-separated fields, you could use: cut -d ' ' -f 7- If you know that your time stamp always occupies 30 characters, you can use: cut -c 31- If you know that your time stamps end with a digit, followed by a colon, followed by a space, and that your data does not include this pattern, you can use: ...


2

Looks like your dollar sign in the 12th variable is in the wrong place. export TYPE_RELN_IDS="{$12}" should be export TYPE_RELN_IDS="${12}"



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