Tag Info

New answers tagged

0

The short answer is that <, >, and their variants have the highest binding precedence (tightest binding), followed by |, followed by && and ||, followed by ; and &.  So, only the echo "Thumbnail creation failed" is piped into the tee. A slightly longer answer would point out that the highest precedence is actually grouping, which can be ...


0

Found solution: clean and easy for i in ${array1[@]};do echo -e "PACKAGE NAME:$i " >> MANIFEST2 && echo -e "PACKAGE SIZE: `xz -l $i |tail -n 1|cut -d . -f 1|awk '{print $3, "K"}'`" >> PACKAGES.TXT PACKAGE NAME:a/pam-1.1.8-x86_64-2mg.txz PACKAGE SIZE: 453 K PACKAGE NAME:x/tvtime-1.0.2-x86_64-3_SBo.txz PACKAGE SIZE: 606 K


0

function readPip() { echo "Enter your partener IP" read ip export PIP= $ip } The space after the equals sign is a syntax error. But in addition, all of this could be refactored to just readPip () { read -p "Enter your partner's IP: " PIP } The export is unnecessary as you don't need external child processes to have access to this ...


0

There are two variables that control the history size: HISTFILESIZE The maximum number of lines contained in the history file. When this variable is assigned a value, the history file is truncated, if necessary, to contain no more than that number of lines by removing the oldest entries. The history file is also truncated to this ...


1

Default size of the history file is 500 lines. Once the .bash_history file reaches 500 lines, the early entries get eliminated to make room for the newer lines, as in FIFO. You can change this by changing the value of the variable HISTFILESIZE which by default has the value 500. Putting a HISTFILESIZE=10000 in your .bashrc will increase the number of lines ...


1

Read man bash for more details covered about bash history like: HISTCONTROL A colon-separated list of values controlling how commands are saved on the history list. If the list of values includes ignorespace, lines which begin with a space character are not saved in the history list. A value of ignoredups causes lines matching ...


1

Given the fact your arrays only have one element and that you test a constant variable, your script, as it is written is equivalent to: #!/bin/sh bridge="gbr0" CSIF="eth2" echo Starting service bridge $bridge brctl addbr $bridge || RETVAL=1 brctl stp $bridge on brctl setbridgeprio $bridge 65000 echo Adding CSIF $CSIF on $bridge ifup $CSIF brctl addif ...


0

Wrap both nc calls with unbuffered sed calls: sed -u "s/^/My name: /" | nc PARTNER_IP 2015 sed -u "s/^/Partner name: /" | nc -l 2015


3

Yes you are correct. The return procedure will exit from the function to the originating caller in the script with an exit status of 1. Therefore the mount command will never get processed. To resolve this, just strip the if .. then statement from the mount command: [ -d ${MKAPP_BUILDDIR}/tmp ] || mkdir ${MKAPP_BUILDDIR}/tmp || return 1 mount -t tmpfs ...


1

The following sed plus gawk (GNU awk) solution performs the requested task: sed -e '/ .BYTE/{s/\$/0x/g;s/,//g}' INPUTFILE.txt | gawk --non-decimal-data '/.BYTE.*0x/{ printf ".BYTE $%x, $%x\n", ($5+$4*4+$3*16+$2*64 ) , ($9+$8*4+$7*16+$6*64) };!/.BYTE.*0x/{print}' The sed call replaces $01 with 0x01 and delete commas in the .BYTE lines which ...


-2

This is exactly what you need: ls -Aru | tail -n 1


1

Readline already has vi-fword and vi-bword which use whitespace as word boundaries so there's no need for Gilles's forward_whitespace_word function. vi-fword followed by unix-word-rubout (\C-w) deletes a whitespace-delimited word backward (including trailing spaces). bind '"\eb":vi-bword' bind '"\ef":vi-fword' bind '"\ed":"\ef\C-w"' vi-backward-word is ...


2

I am not aware of any size limits for here-doc. I'm running kernel 3.9.1 and I've been experiencing the same issue here: when pasting large chunks of text in terminal some lines are truncated or missing. I found out (after some googling) that if you turn off line editing, pasting works fine (discussion here: Pasting large amounts of text into ...


0

I had this issue too and I solved it by using EOF. This is starting a ssh connection to sshserverhost that executes test.sh with parameter $HOSTNAME on the remote server (sshserverhost). at now + 1 minutes <<EOF ssh -t sshserverhost 'bash -s' <~/test.sh $HOSTNAME EOF


2

You were close, but you should use single quotes, not double quotes: kill_stopped='kill `jobs -p` ' Backticks are expanded inside double quotes, so it was running jobs -p at the time you defined the alias, not when you used it.


1

Try this: alias kill_stopped="kill \$(jobs -p)" and to kill runnings jobs: kill_stopped If there are no running jobs you get a message about the usage of the kill.


0

The two commands produce the same output only for your input but otherwise they are different. For understanding of what is going on we have to know how is the parameter interpreted first by bash and then by grep. Escaping in bash \ is a special character which cancels special meaning of the following character including \ itself. If the following ...


0

You could probably use git branches for this. Set your home dir up in a branch and then create another branch and configure this how you'd like for this other "profile". It would be a matter of switching branch and then you'd have effectively a different looking home dir. Then you'd probably need to source your environment or run another login shell. I ...


0

I suppose you have to do this in pure Bash script, but translating John1024's algorithm to awk gives a considerable speed-up: awk 'BEGIN{k=0;for(i=10000;i<100000;i++){j=i;if(gsub(/[456]/,"",j)==2)k+=i};print k}' This runs in less than 1/20 of the time that the bash version takes; it's also a little faster than a Python version that uses Python's ...


0

Getting started Whenever I have a project like this I like to approach it in stages. The first thing I like to do is add an echo to the inside the loop and then run it, to make sure that the loop is giving me what I want. #! /bin/bash for (( CON1=10000; CON1<=99999; CON1++ )) ; do echo $CON1 done Now when I run it I'll use head -5 to just show the ...


2

Here is one way of counting how many 4, 5, or 6 appear in your number and having bash execute a statement based on whether the result is two or not: $ con1=1457 $ a=${con1//[^456]/}; [ ${#a} -eq 2 ] && echo Yes Yes


4

The output is the same only for your string, but in general those regular expressions do different things. Let's modify your example a little by adding second pattern e,g, (with comas), third e\.g\. (dots), fourth e\,g\, (comas), and -o option to grep to print only matched parts. In the following case . match any char (notice '' around e.g., I will come to ...


3

When you do a grep e\.g\., the shell is consuming the backslash, thus you are doing a grep e.g., which matches. When you do a grep e\\.g\\., the shell is again consuming a slash, and now you are doing a grep e\.\g., which again matches. Now, a backslash to the shell looks like \\. So, when you have \\, the first one is an escape sequence, the second is a ...


7

First, note that the single slash matches too much: $ echo $'eegg \n e.g.' | grep e\.g\. eegg e.g. As far as Bash is concerned, an escaped period is the same as a period. Bash passes on the period to grep. For grep, a period matches anything. Now, consider: $ echo $'eegg \n e.g.' | grep e\\.g\\. e.g. $ echo $'eegg \n e.g.' | grep e\\\.g\\\. e.g. $ ...


0

I would have implemented it more like this: #!/usr/bin/python import os, shutil, subprocess filename = "backup.zip" home = "/home/nalangi" tempfile = "backupTEMP.zip" if os.path.exists(os.path.join(home, filename)): subprocess.call(["zip", "-9", "-r", tempfile, "wso2am-1.7.1"]) os.remove(os.path.join(home, filename) shutil.move(os.path.join(home, ...


3

There are at least two mistakes in your cron script: First, you should do a set -e at the beginning so that any error will end the script immediately. Moreover since you are using relative pathnames, you should do a cd to the wanted working directory: cd /home/nalangi Note. The cron(8) man page says: When executing commands, any output is mailed to ...


2

I found these 2 method via Google, in this thread titled: Re: Flattening PDF Files at the UNIX Command Line. Method #1 - using Imagemagick's convert: $ convert orig.pdf flattened.pdf NOTE: The quality is reported to be so so with this approach. Method #2 - Using pdf2ps -> ps2pdf: $ pdf2ps orig.pdf - | ps2pdf - flattened.pdf NOTE: This method is ...


2

Here's another one using the output formatting from ps: #!/usr/bin/sh -f printf '%-8.7s%-8s%s\n' $( ps -o uname=UID,pid=PID,args=APPNAME | sed -n '1p;s/\( [0-9]* \).*\(-Dapp.name=[^ ]*\).*/\1\2/p' ) Based on its format string, for every 3 of its arguments printf will print: The first space-padded on the right to a standard tab-width of 8 ...


3

For general purpose tabular alignment, you want the column utility. For example: ( printf 'PID\tUSER\tAPPNAME\n' printf '%s\t%s\t%s\n' "1" "john" "foo bar" printf '%s\t%s\t%s\n' "12345678" "someone_with_a_long_name" "pop tart" ) | column -t -s $'\t' Results in: PID USER APPNAME 1 john foo bar ...


1

Also can this script be optimized into one line command? I'd consider using the -o option of the ps command to output (as far as possible) only the fields of interest, and then post-processing that to match the java processes and specific command argument(s) that you require - something like ps -u $USER -o uname=,pid=,args= | gawk -vOFS='\t' ...


1

You are on the right track with the ${:+} expansion operator, you just need to modify it slightly: V=${V:+${V}:}new_V The first braces expand to $V and the colon iff V is set already otherwise to nothing - which is exactly what you need (and probably also one of the reasons for the existence of the operator). Thus in your case: export ...


-2

Another, using the bash options set internal variable, $-. From .bashrc, # If not running interactively, don't do anything case $- in *i*) ;; *) return;; esac


1

You need to single quote your here document limit string, otherwise parameter substitution will be enabled. This should work: #!/bin/bash cat server | while read line do /usr/bin/sshpass -e ssh -t -q -o StrictHostKeyChecking=no root@$line <<'EOF' echo successfully logged in $line MYIP=$(ifconfig | sed -En 's/127.0.0.1//;s/.*inet ...


5

From man bash under CONDITIONAL EXPRESSIONS: -t fd True if file descriptor fd is open and refers to a terminal. Assuming fd 1 is standard out, if [ -t 1 ]; then should work for you. The Advanced Shell Scripting Guide claims that -t used this way will fail over ssh, and that the test (using stdin, not stdout) should therefore be: if [[ -t 0 || -p ...


0

Test for the existence of the PS1 environment variable: # If $PS1 is null, not being run from a shell if [ -z $PS1 ] Alternatively you can test for it being not null, i.e., run from the shell if [ -n $PS1 ]


0

But are there any solutions that is the same as crunch, the only difference is that is randomly outputs the lines? No. This problem can be solved only in two steps: Create all possible combinations Generate random permutation of result You cannot do both at the same time, at least not with single algorithm for creating combinations. You would ...


0

Well, you could just pipe everything after the output line that starts with 'Crunch will now' through sort -R. Like this: crunch 3 3 ab| sed -e '0,/^Crunch will now/d' | sort -R Still not sure if this counts as 'on the fly', though.


1

Mimicking crunch Something like this will generate all the permutations of the set {a,b} @ 3 strings long, and it will shuffle up the output using shuf. $ printf "%s\n" {a..b}{a..b}{a..b} | shuf bbb aab abb bba baa aba bab aaa This is really no different though than using sort -R. Hiding the randomizing If you're intending to hide the interface so ...


0

Try: chmod 0755 /etc as root. You could have run into an issue with the /etc directory's permissions being wrong. Also revert the permissions of the bash.bashrc file to their original permissions chmod 644 /etc/bash.bashrc.


4

You simply need to use the eval shell builtin: $ eval ls {$(seq -s , 13 20)}.pdf Where eval takes the arguments passed to it: ls {$(seq -s , 13 20)}.pdf and concatenates them together into a single command: ls {13,14,15,16,17,18,19,20}.pdf which is then read and executed by the shell. $ eval ls {$(seq -s , 13 20)}.pdf 13.pdf 14.pdf 15.pdf 16.pdf ...


4

@artm showed a technique where you double-quote the awk script and escape various characters. Here are 3 other techniques Break out of the single quote to let the shell expand the variable usrpid=$(awk '$1 == "'"$USR"'" {print $2}' file) Pass the shell variable into an awk variable usrpid=$(awk -v usr="$USR" '$1 == usr {print $2}' file) If the ...


1

the "$USR" in the first example isn't expaneded because it occures inside single quoted string '$1 == "$USR" { print $2 }', so this code is looking for a row with the first column being "$USR", not 62. The following should work: usrpid=$(awk "\$1 == \"$USR\" {print \$2}" /home/hu/batchhu/dbscripts_tst2/user-pid.out2) Changes: the awk command line ...


0

An easier solution: 1.- ssh user@host 2.- $ sudo su 3.- # xauth merge /home/user/.Xauthority That’s all Of course $DISPLAY variable must be set.


2

have you tried ls $(seq -f %.0f.pdf 13 20 ) -f gives the format string .0f for 0 decimal digit float .pdf obvious (and you know about $( ) syntax)


2

Yes, it is. If you want to do two things concurrently, and wait for them both to complete, you can do something like: sh ./stay/get_it_ios.sh & PIDIOS=$! sh ./stay/get_it_mix.sh & PIDMIX=$! wait $PIDIOS wait $PIDMIX Your script will then run both scripts in parallel, and wait for both scripts to complete before continuing.


2

In bash, different commands have different notions of words. C-w kills to the previous whitespace, but most other commands including M-t use punctuation-delimited words. With the cursor between the first and second argument, C-w C-e SPC C-y will transpose the two words. If you want to bind a key to transposing whitespace-delimited words, it's more ...


1

Unquoted newlines in command lines get treated as spaces; that's why you can say things like command1 && command2 Well, sometimes unquoted newlines get treated like semicolons.  But, when you say echo `cat ${log}` all the newlines in the log file get turned into spaces.  You could fix this by saying echo "`cat ${log}`" but why not just say cat ...


4

You need spaces around the [ and ], e.g. if [ "$MARK" -ge 0 -a "$MARK" -lt 50 ]; then The way you wrote it, when $MARK is 7, it tries to execute the [7 command instead of passing 7 as an argument to the [ command ([ is just a short name for test). You should also quote the variable. Otherwise, if the user enters a blank line or multiple words, the test ...


0

Perl solution: #!/usr/bin/perl use warnings; use strict; use feature qw{ say }; my %values; while (<DATA>) { next if /^$/; # Skip empty lines my ($lane, $sample, $var, $val) = split; die "Duplicate $lane $sample $var\n" if $values{$lane}{$var}{$val}{$sample}; $values{$lane}{$var}{$val}{$sample} = 1; } my %results; for my $lane (keys ...


2

If your cursor is there: vimdiff projectOne/Vagrantfile projectTwo/Vagrantfile ^ Press Alt + BTTBBTFTBBTT Or simple: Press Ctrl + W, Ctrl + E, insert a whitespace and press Ctrl + Y



Top 50 recent answers are included