Tag Info

New answers tagged


var=$( cat foo.txt ) would store the output of the cat in variable var. var=$( ./myscript ) would store the output of myscript in the same variable.


For me it was the baudrate too low. Output did appear once I reconfigured the system (device and port) to use 300 instead of 150.


Don't try to build a shell script from a list of files, it's hard to get right and almost always a lot harder than directly executing whatever you need to execute. Instead, when you have the file name available, go ahead and rename it. #!/bin/sh number=1 while IFS= read -r old_name; do new_name=$(printf %04d "$number").jpeg number=$((number+1)) mv -- ...


set IP_ADDR = "" is incorrect. You need: IP_ADDR="" (without spaces).


#!/bin/sh for i in {01..84} do cat $i*.csv > $i.csv-concat rm $i*.csv mv $i.csv-concat $i.csv done don't forget cat, it's a concatenation tool, tail can also do the job and remove header. #!/bin/sh pushd [workdir] for i in {01..84} do echo $i*.csv | xargs -n 1 tail -n+2 > $i.csv-concat rm $i*.csv mv $i.csv-concat $i.csv done popd


#!/bin/bash for i in {01..84}; do x=$(printf '%02d' $i) set -- $x?*.csv if [ -f "$1" ]; then cp "$1" $i.csv shift if [ -f "$1" ]; then tail -q -n +2 "$@" >> $x.csv fi fi done For each prefix, it sets the list of files with that prefix as the arguments so that you can use $1 to access the ...


system() function of awk can be used for this. $ awk '{system("curl -v www.google.com/"$1"/testing/"$2"/"$3"/works/"$4)}' file.txt Here file.txt contains the arguments to curl command.


I don't think you can do this directly with xargs. Either use read as Costas suggests, or do: xargs -n5 sh -c 'curl "http://www.google.com/${1}/testing/${2}/${3}/works/${5}"' curl-command Or build the URL, then pass it to xargs: awk '{printf "http://www.google.com/%s/testing/%s/%s/works/%s\n", $1, $2, $3, $5}' | \ xargs -L1 curl


My guess is that less calls isatty(3) on file descriptor 0. Another alternative would be to call fstat(2) on file descriptor 0 and interpret the values of the st_ino and st_rdev fields. Either way, the point is a program can tell something about a file descriptor, and stdin is just file descriptor 0. As far as why less exits and cat does not, you need to ...


less runs the following code when it's not given any filename arguments: if (isatty(fd0)) { error("Missing filename (\"less --help\" for help)", NULL_PARG); quit(QUIT_OK); } return (edit("-")); It's complaining when standard input is a terminal. If standard input is an ordinary file or pipe, it's OK with that. It presumably does this because it ...


The Ctrl-O option has been in Unix since the 110 baud days. Runaway cat commands were always a problem when a long ASCII file was dumped at the slow output device and the the entire file placed in the device driver output buffer. Ctrl-O would start the flush of the buffer and a follow up Ctrl-O would toggle off the flush so the cat could be read at normal ...


That's because Ctrl+D is a hack. Deep down, Ctrl+D (despite being called the eof character) doesn't actually mean end-of-file: it means “send the pending input to the application now”. This is actually close to the meaning of Ctrl+M (eol), which sends the pending input plus a newline. When you press Ctrl+D immediately after a Ctrl+M (i.e. at the beginning ...


In Unix, most objects you can read and write - ordinary files, pipes, terminals, raw disk drives - are all made to resemble files. A program like cat reads from its standard input like this: n = read(0, buffer, 512); which asks for 512 bytes. n is the number of bytes actually read, or -1 if there's an error. If you did this repeatedly with an ordinary ...


This is what tmux option c0-change-interval and c0-change-trigger designed for. You should use a screen manager for resumable session anyway.

Top 50 recent answers are included