Tag Info

New answers tagged

0

It depends on your shell and the supported features. With bash, e.g., you can type: !330 my_computer.sh


1

Most shells restrict the name of functions to contain only characters that don't need to be quoted, which excludes >. Even in the few shells that allow > as a function name (I only know of zsh), defining a function called > would only have an effect if you called > as a command (which would require quoting it, i.e. running \> or ">" or ...


1

if your test.bash looks like this: echo "Hello World!"; echo error >&2 this script loop.sh: ./test.bash &> original ; echo original: ; cat original; ok=0 ; er=0 for i in {1..100}; do rm output ; printf "(ok%d:er%d) running again: " $ok $er ./test.bash 2> >(cat >>output) > >(cat >>output) #<-EXAMINED ...


0

If all of your input lines start with either stderr: or stdout:, you could do: perl -ne 's/^std(...):\s*//; $1 eq "err" ? print STDERR : print' output Or, with recent versions of bash while read -r out line; do [[ $out =~ ^stderr ]] && echo "$line" >&2 || echo "$line" done < output


4

Depending on your current file probably this would do: awk ' /^stdout:/ { print substr($0, 9) } /^stderr:/ { print substr($0, 9) > "/dev/stderr" } ' output It could get a bit more elegant with some changes to your "recording script".


1

The > has a special meaning in the shell, it's a redirection operator, see the manpage: [n]> file Redirect standard output (or n) to file. The name of a function can contain only letters (a-z or A-Z), digit (0-9) or the underscore character (_). Also is must not begin with a digit. (see Function Definition Command and Name)


5

You can try things out with a script such as #!/bin/sh for fd in 0 1 2; do if [ -t $fd ]; then echo $fd is a TTY; fi done Running this I see that: if the script is run on its own, all three FDs are TTYs if the script is run at the start of a pipeline, stdin and stderr are TTYs if the script is run in the middle of a pipeline, stderr is a TTY if the ...


3

You don't make a backup with gzip into a directory, but into a different file: gzip < file.in > file.out or in your case: filelocation=/home/user/image.img backuplocation=/home/image.img.gz gzip < "$filelocation" > "$backuplocation" based on that you can do: gunzip < "$backuplocation" > /some/new/location/image.img


2

You have various options... To pass shell variables to awk and use them in string comparison and let the shell create the file: awk -v chr="$chr" '$1==chr' "$infile" > "exons_${chr}.bed" To additionally let awk do the output into the file: awk -v chr="$chr" '$1==chr { print > "exons_" chr ".bed" }' "$infile"


0

Thanks for the input, it did not work for Python scripts because it was buffering the output. This allows it to work with tee: python -u ./myscript.py | tee /dev/tty1 /tmp/a.txt


1

If you want to save the output of a command, use the script command script -c "your command" /tmp/capture.txt The output will be sent to the tty and also to capture.txt If tty1 is not the console that you are running from, you could run a tail -F /tmp/capture.txt from that tty in order to get the results there as well.


0

Others have mentioned that your standard input is being replaced by your streamed script. This is a common problem, but is easily solved: bash 3<&0 <<\SCRIPT #ref stdin in fd 3, replace stdin w/ SCRIPT echo Doing some stuff... #do your stuff printf "\r [ \033[0;33m?\033[0m ] What is your name? " read -e name <&3 ...


0

The standard input of the bash process is the script that's being downloaded by wget. So the call to read reads a line from that script, or reads nothing if bash has already finished the script. wget -O - … | bash may be a cute one-liner, but it is not a good idea. If the download breaks in the middle, bash will execute the part of the script that could be ...


0

Thought: You're running bash with a pipe to standard input. And then you're asking it to read from standard input. That won't work. Use a named pipe instead? ETA: Or maybe not … mkfifo ~/tmp-pipe wget -O - https://raw.githubusercontent.com/caarlos0/dotfiles/install/script/install > ~/tmp-pipe & bash ~/tmp-pipe rm ~/tmp-pipe By this time, if you ...


-1

This is due to > being interpreted by the outer shell. The command being run does not know of the redirection, and thus it cannot pass that as an argument to the function. In other words: The > is already executed before sudo is run. What you can do is to have a command called save: save() { sudo tee "$@" >/dev/null } echo something | save ...


1

You probably wanted to pass all as one argument: function pipe { sudo bash -c "$@" } pipe 'echo something > /etc/importantfile'


1

As Janis says, it appends a newline. Anything that changes the existing exact sequence of bytes in the file will cause the MD5 checksum to be altered. The ISO image will still work as it's an image of an ISO9660 (CDROM) filesystem, and the filesystem know what its bounds are and won't get confused by extra data beyond the end of a filesystem. However some ...


4

The command will output the data from device /dev/null to the given file (mailbox of the root account). Since /dev/null responds just with end-of-file when reading from it nothing will be written to the file, but with the redirection > the shell will have cleared the file already. Actually this is equivalent to writing just > /var/spool/mail/root ...


1

cat /dev/null > /var/spool/mail/root truncates /var/spool/mail/root Alternative is > /var/spool/mail/root


2

As I understand it (the <<EOF2 stuff at the end isn't crystal-clear), the end result you're after is to feed the following into sqlplus64: @update.sql AAA 30 @update.sql ABC 10 @update.sql EDF 30 To produce this, instead of looping over the contents of both files, you can combine them. Using paste on both files (paste doc1.lst doc2.lst) gives AAA ...


1

You have to clear those escapes as you read them - do what the terminal does and overwrite them. This emulates the output you describe w/ seq: seq -s " $(printf '\033[A')" 10 If it writes out to a terminal which interprets that escape it will appear to print only 10. But as you note in the question, it's really printing all of those numbers over one ...


2

What you want is already happening, actually. And certainly mkdir isn't your problem - it doesn't read stdin anyway. That pipe is inherited as stdin by all of the children of ssh - unless, that is, you are getting a pseudo terminal like ssh -t. Barring that, then the problem is that the shell running those commands is one of ssh's children - and part of ...


1

Bash can't modify the file descriptors of a running process. See answers for How to change the output redirection of a running process? (or a similar thread on stackoverflow) The easiest and only current tool seems to be reredirect: reredirect is a utility for taking an existing running program and attaching its outputs (standard output and error ...


3

You can redirect the first command's stdin from /dev/null: anthony@Watt:~$ echo -e 'hello\nworld' | ssh localhost 'cat < /dev/null && cat -n' 1 hello 2 world The lines are numbered, so the 2nd cat got them. If not using ssh in there, you'd use a subshell: echo -e 'hello\nworld' | ( cat < /dev/null && cat -n )


3

If myExe is in ./ and it defaults to writing to 4 files in ./ but you instead want those 4 files in /myfolder then you can do: (cd /myfolder && "$OLDPWD/myExe" params) ...which will still write those 4 files to ./ but change the value of ./ to /myfolder for only the length of time it takes to for ./myExe to write them.


3

The error is because you are redirecting all output to $logfile so there is no output for yad to process. The tool you're looking for is tee: NAME tee - read from standard input and write to standard output and files SYNOPSIS tee [OPTION]... [FILE]... DESCRIPTION Copy standard input to each FILE, and also to standard output. So, you ...


1

Not certain what your trying to do, but here is something that worked for me. (drat having trouble keep stackexchange text editor from treating the back ticks as formatting characters, using forward ones for where I mean back ticks) R='ssh -t hostname <<EOF ls -l EOF' Note that I don't close the backtick until after EOF and use -t option to create ...


1

If you wrap the entire command that you want executed inside backticks it's likely you'll get the correct solution. There are issues regarding the evaluation of variables and other interpolated elements, but I'll put those to one side for a moment. However, I'm not entirely sure why you want anything in backticks. Your Question says you want to run a local ...


0

To capture and test for error output: ls -l test 2>errors if [ -s errors ]; then echo "There were errors:" && cat errors; fi rm errors


1

2>&1 duplicates standard output as standard error. </dev/null redirects standard input to the null character special device, eof is encountered immediately when reading. |head -n1 pipes standard output to the command, thus the first line is printed, and lines after the first are discarded.



Top 50 recent answers are included