Linked Questions

5
votes
1answer
1k views

cat and pipe vs. redirection [duplicate]

What's the difference between these two commands? cat /proc/uptime | awk '{print $1}' < /proc/uptime awk '{print $1}' Specifically, how does the second command work? Doesn't the redirection ...
0
votes
0answers
59 views

How does this echo command work? “echo > file.txt Hello” [duplicate]

I know you can redirect the output of echo to a file using this syntax: $ echo "Hello" > file.txt But I recently discovered a different way of producing the same output as above which is: $ echo ...
233
votes
3answers
94k views

What are the shell's control and redirection operators?

I often see tutorials online that connect various commands with different symbols. For example: command1 | command2 command1 & command2 command1 || command2 command1 && command2 ...
22
votes
2answers
2k views

cat gives different error when opening non-existing file

Both of the following commands try to open a non-existing file foo, but the error messages are a little different. What could be the reason? $ cat foo cat: cannot open foo $ cat < foo -bash: foo: ...
2
votes
1answer
3k views

How to a grep a word from a file and store it into another existing file?

How to a grep a word from a file and store it into another existing file? What I've tried is cat q1.txt | grep -i "osx" test.txt I want to grep it from test.txt and store it into q1, but this and ...
3
votes
3answers
1k views

Redirect content under a new line (without further syntax or arguments)

I tried these ways to append content to a file: printf "\nsource ~/script.sh" >> /etc/bash.bashrc echo -e "\nsource ~/script.sh" >> /etc/bash.bashrc cat >> "/etc/bash.bashrc" <&...
0
votes
1answer
356 views

Correct location for piping and redirecting output in find -exec?

I'm using find with the -exec option in console, on FreeBSD (for example, find . -exec sha1 {} \;). How do I correctly place (and if needed, escape) redirect and other execution control symbols that ...
3
votes
1answer
315 views

How to execute local script by passing arguments on remote via ssh as a different user?

I am trying to execute a local script on remote server via ssh using keytab authentication. I am able to connect to remote via ssh as sachin(user who gets the ticket) and then I am spawning a bash ...
-1
votes
2answers
80 views

What does this command do (strange assignments and redirections) [closed]

I would like to get more details on what the below command is doing: PASSING=0 FAILED=0 > log_${ENV} print "Test Started at `date`\n"
0
votes
2answers
75 views

How could I know inside a script if stdout has been redirected for it?

I have a script in ksh; depending whether there is a redirection from the command line, I redirect the output via a exec 1>file. How can I test from inside the script itself if the command calling ...
1
vote
1answer
57 views

Why reverse syntax of output redirection doesn't act as input redirection?

command 1: cat file1 > file2 (success) command 2: file2 < cat file1 (cat : No such file or directory) I just wanted to know the general syntax of output and input redirections. If redirection ...