Tag Info

New answers tagged

0

Simple example of escaping quotes in shell: $ echo 'abc'\''abc' abc'abc $ echo "abc"\""abc" abc"abc It's done by finishing already opened one ('), placing escaped one (\'), then opening another one ('). Alternatively: $ echo 'abc'"'"'abc' abc'abc $ echo "abc"'"'"abc" abc"abc It's done by finishing already opened one ('), placing quote in another quote ...


1

Here is escaped command: alias mm='ps -u $USER -o pid,rss,command | \ awk '\''{print $0}{sum+=$2} END {print "Total", sum/1024, "MB"}'\' Example of escaping quotes in shell: $ echo 'abc'\''abc' abc'abc $ echo "abc"\""abc" abc"abc It's simply done by finishing already opened one ('), placing escaped one (\'), then opening another one ('). ...


0

Is this the bug you're talking about? Apparently, there is some code hacking that needs to be done... to make it work. I found out that on iPad this.isEmbedded isn't set correctly. It seems that the Mobile Safari doesn't support some attributes for the screen. So this.isEmbedded is set to true, when it shouldn't be. A quick hack: In vt100.js add the ...


0

I've faced the same issue and I'm not allowed to run anything other than sudo su - devuser on dev server, so this is what I came up with: In devuser's .profile switch back to previous user home if found: prev_user_home=$(~/bin/home.sh) if [ -n $prev_user_home ] ; then cd $prev_user_home fi A script to determine a previous user. The script is ...


1

The POSIX spec really hedges its bets where the Controlling Terminal is concerned, and which it defines thus: Controlling Terminal The question of which of possibly several special files referring to the terminal is meant is not addressed in POSIX.1. The pathname /dev/tty is a synonym for the controlling terminal associated with a process. That's in ...


4

The "controlling terminal" aka. CTTY, is distincted from "the terminal a process is interacting with". Standard compliant way of getting the path of ctty is ctermid(3). While in freebsd an actual path is looked up[1], the implementation in glibc as of version 2.21 unconditionally returns "/dev/tty"[2]. ps(1) from the linux procps 3.2.8 package, read the ...


0

Another option for simple web pages is 'lynx' which has a -dump option. It will save to a file a 'readable' view of the web pages content. lynx is a bit old and hairy now, and doesn't support either javascript nor frames. But if your trying to strip out 'human readable' content from a flat low/non-interactive web page, it a bit simpler to work with than ...


2

To collect the two lines separated by a newline in a variable... while read line1 && read line2 do bothlines=$line1$'\n'$line2 do_something_with "$bothlines" done < test.fa (works with ksh, bash, zsh)


0

Based on @DigitalTrauma answer, this is what worked for me at last: size=$(stat -c %s file) dd bs=2 if=file skip=1 seek=0 conv=notrunc count=511 of=file dd if=file ibs=1024 skip=1 of=file conv=notrunc obs=1022 seek=1 truncate file $(( size - 2 )) Removing the first two bytes is done over 2 dd steps to speed things up and truncate is a small utility to ...


0

If you want to avoid a multi-pass through your data with a fixed subset of IDs given, this is one possible way (for sample indexes 1, 2, 10): sed -n '/INDEX : \(1\|2\|10\)$/,+28p'


2

It appears you're trying to use ttyS0 as a means to connect two processes. This won't work reliably since ttyS0 is the interface to a serial line (COM1: in Windows-speak). On the other hand, it might be that information is missing from your question. If you really do have a device on your serial port, please make that clear. What I believe you're looking ...


3

Another approach: awk 'BEGIN{FS=":|\n";RS=""}NR==1{print $1,$3,$5,$7,$9}{print $2,$4,$6,$8,$10}'


1

You may want to put the header manually and run the following awk on the file: awk -F: '{count++; printf("%s ",$2); if (count>5){count=0; printf("\n");}}' x.txt >> res.txt Assuming x.txt contains the inputs as you have and res.txt is a prepared file with headers as follows: name sub branch DOB company The resulting output will be: name sub ...


6

Every command in Linux returns an exit code when it finishes running. The exit code is assigned to a special variable ?, so you can easily check the status of last command, e.g. by echo $?. This is often utilised in scripts. If the command finishes successfully, it returns an exit code 0, whereas if there are any errors during the execution, the exit status ...


4

In addition to @heemayl's answer, && (and also ||) will result in the shell only handling a single exit code for all the chained commands. So if you have a trap [...] ERR or set -o errexit line it will process all the commands before doing the exit code handling.


1

You need to quote the URL, otherwise the & signs will be interpreted as command delimiters. That said, you can either redirect the curl output to a file (curl [...] > index.html) or use wget, which saves to file by default.


21

echo "Hello " ; echo "world" means run echo "world" no matter what the exit status of the previous command echo "Hello" is i.e. echo "world" will run irrespective of success or failure of the command echo "Hello". Whereas in case of echo "Hello " && echo "world", echo "world" will only run if the first command (echo "Hello") is a success (i.e. exit ...


1

I think this should work: $ # Create test file $ echo "Hello, World" > h.data $ $ # Move contents up by 2 bytes $ # Note if= and of= are the same for in-place editing $ dd bs=2 if=h.data skip=1 seek=0 conv=notrunc of=h.data 5+1 records in 5+1 records out 11 bytes (11 B) copied, 0.000598796 s, 18.4 kB/s $ $ # Note 11 bytes were moved above $ # ...


1

You can put relative paths in the search path. It's dangerous, because it could cause you to execute unexpected binaries when you're in a directory which isn't part of your project; don't do it on a multi-user machine. PATH=…;node_modules/.bin/ionic;… For more safety and flexibility, you can change the search path each time the current directory changes. ...


2

First, your snippet executes the command echo {} : ;if [ -f {} ]; then echo file; else echo directory;fi because it needs its output to evaluate the command substitution. Since there is no file named {}, this produces the output {} : directory Then the find command is executed with the arguments -exec, echo, {}, :, directory, so for every file, it ...


-1

This is how I used it: f() { ls $AAA return $? } g() { f return $? } d() { g echo $? } AAA= d _ <contents of dir> 0 _ AAA=sdsasdasd d _ ls: sdsasdasd: No such file or directory 2


0

You cannot put a space after filename= Remove the space and you will be good.


1

Why first assign the timestamp to value? You can just do: filename="/home/pi/media/"$(timestamp)".h264" And you should quote the filename in the recording command (in case there are spaces in the path, etc.): #Recording raspivid -w 800 -h 600 -t 15000 -o "$filename" -n -rot 270


8

The problem is that you'll be checking the exit status of pv. With POSIX sh syntax, you could do: cd /app && ((make 3>&- && exec sudo nginx -g 'daemon off;' >&3 3>&-) | pv -qL 100) 3>&1 Or with ksh/bash/zsh: (set -o pipefail cd /app && make | pv -qL 100 && sudo nginx -g 'daemon off;') Or with ...


0

I don't know if it is clear but you may be interrupting the loop when you are using break and exit set -A arrs a b c d num=`expr ${#arrs[*]} - 1` for x in `seq 0 $num` do var1=`some command here` var2=`some command here` var3=`some command here` if [[ "$var1" == "$var2" && "$var3" == "0" ]] then #do something here ...


1

You added break in the yes statement, so it is exiting the for-loop and therefore not finish testing the rest of the array. Just remove break from the 'yes' case statement. I tested with some modifications to your code, and got what I believe are your expected results: #!/bin/sh arrs=(a b c d) num=`expr ${#arrs[*]} - 1` for x in `seq 0 $num` do ...


0

You could use grep with -f: -f FILE, --file=FILE Obtain patterns from FILE, one per line. but for that you need to format your identifiers file accordingly, e.g. it should read: INDEX : 1 INDEX : 10 .......... INDEX : 100 instead of: 1,10....100 If you use - as FILE grep will read patterns from stdin so, one way, with awk (and also ...


1

When you have fixed entries for the identifiers you like, you can use for identifier in 1 10 20 30; do grep -A 28 "INDEX : ${identifier}$" Test.txt done When you do not have fixed identifiers, you might grep without specifying the identifier: grep -A 28 "^INDEX : " Test.txt I use ^ here for matching INDEX lines at the beginning of the line.


6

OS installation date is ambiguous: what counts as a new installation? If all the files are new after update, is it still the same installation? The "official" setup script may record the date, but this is distribution dependent and most distros won't do that. However, you can always check the earliest date of the files in /bin/, /etc/ and /boot/, most of ...


1

The simplest way would be to use zsh's numeric range glob: mv PRC<257-1516> /else/where/ The range operator matches numbers with or without leading zeroes, so PRC257, PRC0257, PRC00257, etc. are all included. You can leave the end of the range blank, e.g. PRC<257-> to move all files from 257 onwards. It doesn't matter how many files in the ...


2

Just include an actual newline inside the quotes (this works with either single or double quotes). Note that if the second line is indented, the spaces are part of the string. Furthermore always use double quotes around variable substitutions. str="deb http://ftp.cn.debian.org/debian/ wheezy main contrib non-free deb-src http://ftp.cn.debian.org/debian/ ...


0

Inside awk you don't have direct access to shell variables, you need to pass them as an options, so change awk command to something like: awk -v SF="$SCALINGFACTOR" '{printf($1"\t"$2"\t"$3"\t"$4*SF)}'


3

Two brace expansions do work, they just don't work the way you want them to: $ touch abc $ mv {a,}b{c,d} mv: target `bd' is not a directory $ echo mv {a,}b{c,d} mv abc abd bc bd They are expanded separately - effectively the first one is expanded, leaving you with mv ab{c,d} b{c,d} and then the second is expanded, leaving you with mv abc abd bc bd.


0

If you want to work with an arrayed expansion result in a basic POSIX shell you have to take care with both $IFS and filename generation. You can work safely with unquoted variables - but it is usually not the most simple way to do it. Shell's are designed to work first and foremost with arguments - so I suggest you use the argument array: set -- ...


2

You can't use the wildcard as part of the variable if you are also using quotes. Note that in the array variable syntax @jasonwryan suggested, it is looking at the contents of the directory at the time the array is initialized, rather than when the loop is executed. #!/bin/sh DIR='/home/user/.gvfs/analysis$ on ...


0

Verify that you have permissions all the way through to the final subdirectory and @jasonwryan answer should work.


1

You could do a lot of the work w/ shell math so you don't have to fork every few seconds, but you probably would want to work in some sort of synchronizer every once in a while to ensure the time is keeping well. The below loop just sets some initial values for $h, $m, and $s then decrements once every 15 seconds and prints a countdown line at the top-left ...


1

You could use this instead: for c in {A..Z}; do echo -n "$c: " tr ' ' '\n' < dico.txt | grep $c | wc -l done It works as follows: The for loop runs through each character from A to Z. tr replaces all spaces with newlines, so every word has its own line. Then grep searches for the character in the word an prints it if the character is found. wc ...


0

Is it helps? #!/bin/bash tr ' ' '\n' < "$1" | sort -u > my.tmp for letter in {A..Z} do printf "Words with %c : " $letter grep -iwc "\w*$letter\w*" my.tmp echo done rm my.tmp


1

You have to do unset MAILCHECK. From the bash manual: MAILCHECK Specifies how often (in seconds) bash checks for mail. The default is 60 seconds. When it is time to check for mail, the shell does so before displaying the primary prompt. If this variable is unset, or set to a value that is not a number ...


2

Something like t=1 until [ "$t" -le 0 ] do t=$(($(date -d '2015-02-24 16:40:00' +'%s')-$(date +'%s'))) sleep 1 tput clear echo $t done


3

You can use column: $ column -t < file menuNAME menuNAME2 menuNAME3 word word2 THISwordisLongest THISwordisLongest word wordLONG wordLONG THISwordisLongest word


0

One option is to use echo -e to expand the escape sequences. The second option is to simply use a "literal" newline (works in bash): str = "deb ... non-free "$'\n'"deb-src ... non-free " echo "$str" Note the $'···' notation to insert a literal. However, having newlines in variables like this is not a good idea. It's harder to read the script, it could ...


1

Almost all problems with scripts properly running from the commandline, but not from cron come from the setting of the PATH variable. According to man 5 crontab for Vixie cron: On the Debian GNU/Linux system, cron supports the pam_env module, and loads the environment specified by /etc/environment and /etc/secu‐ rity/pam_env.conf. It ...


0

Two options: Option 1 - Have you chmod +x test.sh? That way you can execute with ./test.sh rather than sh test.sh. Option 2 - If you don't want to chmod the file, change your crontab entry to * * * * * /usr/bin/sh /home/username/test.sh Additionally, if you choose the latter, you should verify the sh binary location with which sh


3

Aside from jasonwryan's suggestion, I'd suggest using printf: $ printf "%s http://ftp.cn.debian.org/debian/ wheezy main contrib non-free\n" deb deb-src > test $ cat test deb http://ftp.cn.debian.org/debian/ wheezy main contrib non-free deb-src http://ftp.cn.debian.org/debian/ wheezy main contrib non-free Since printf reuses the format string until ...


1

Select range in braces: cp PRC{0257..1516} destination/


5

The problem here is actually an issue with the bash parser. There is no workaround other than editing and recompiling bash, and the 3333 limit is likely to be the same on all platforms. The bash parser is generated with yacc (or, typically, with bison but in yacc mode). yacc parsers are bottom-up parsers, using the LALR(1) algorithm which builds a finite ...


0

When you get the subproducts you need to use eval: eval subproducts=\$${x}SUBPRODUCTS


4

Two faults There is no such command as source in /bin/sh. Perhaps you meant to write #!/bin/bash on the first line, or use . ./config.cfg instead? The script is failing because you created/edited the file config.cfg on a Windows system and copied the file (in binary mode) to your Unix/Linux system. You can replace the CR/LF line endings with correct LF ...



Top 50 recent answers are included