How to print on stderr without using /dev/stderr [closed] - linux

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
How can a linux command script print warnings or error messages without using >/dev/stderr each time?
This should be simple but I don't get it.
Can you post a simple example?

To print to standard error, use a command that writes to standard output (like echo or printf) and redirect the output to file descriptor 2.
echo "This goes to standard output"
echo "This goes to standard error" >&2
This is the most common use of the file descriptor duplication operator, which makes the descriptor indicated by the preceding number (or 1 if omitted) a copy of the descriptor indicated by the following number.

Every unix process always has three open file descriptors when the process starts.
0 is stdin
1 is stdout
2 is stderr
http://man7.org/linux/man-pages/man3/stdout.3.html

Related

Using BASH FOR LOOP and PARALLEL [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Just want to check if this is possible to automate in PRALLEL?. I have a bash script that reads a text file line per line and then takes the word of that line as a parameter then it will be processed by the bash script. For sample this would be the format of the text file
TEXT FILE
# cat test.txt
dog
cat
fish
rat
dove
Then line per line will be executed by a separate bash script via loop fashion like these
# for word in `cat test.txt`; do ./MY-BASH-SCRIPT.sh ${word}; done
Well this works fine however I it is executed one by one. May I ask for any suggestion on how can I possibly trigger the words in PRALLEL? I've gone and also read the GNU Parallel and gone some test however got no luck yet
this is now solved via parallel command:
cat test.txt | parallel ./MY-BASH-SCRIPT.sh {}

Linux Internal Process for Cat and Grep [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I'm newbie to linux back round process, for example i have the below linux command, Maybe the question will duplicate here but i couldn't find answer so posting it.
cat test.txt | grep hello
how many back round process(s) will run? It would be great if insight on this.
There are two processes: cat and grep.
If you just launch the command line likt that, both processes are not background processes. (I guess you are asking background jobs?)
However, this example is not good, since you can just grep hello test.txt to save one process.
But if you just want to ask the number of processes, it's fine.

Saving Ping command output into a variable with a batch file [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am building a batch-file for some rudimentary ping connection monitoring on my network and i want to know how i might save the output from a ping command to string. later steps i would like to pull specific data out of that string as needed. Then i would like to do things based on the data stored in the string. such as play a sound when packet loss occurs.
Split the ping output line with delimiters Space, Equal, Less, and use 7th token if 8th token is "TTL".
This code works for me, it puts reponse time in miliseconds to environment variable %RESPONSE%:
SET IP=google.com
FOR /F "tokens=1-9 delims==< " %%a IN ('PING -n 1 -w 2500 %IP%') DO IF "%%h"=="TTL" SET RESPONSE=%%g

Script program inputs in bash ubuntu linux [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm in a course for C++ programming.
Our professor created a linux validation script against which our program output must match exactly.
It's running out of his own program and generates an output.txt file, then compares it against his output file, if it doesn't match it rejects the script.
The problem is, this program excepts probably 150-200 lines of input and if anything goes in wrong you have to start all over again. If you even enter an incorrect char, it must be restarted as the backspace registers as a character of its own.
How might I generate a bash script that would feed all of the input into the program automatically?
NOTE: We have to use his program as in: ~professor.name/submit asigname
You can create a text file:
answers.txt
answer1
answer2
...
answerN
and use that as stdin for the program:
./your_program < answers.txt
How might I generate a bash script that would feed all of the input into the program automatically?
Without any example code or input/output, it is hard to gauge what precisely is that you need.
Otherwise, for a generic tool to automate interactive console programs, I would suggest to take a look at the Expect.

What does "|" mean in a terminal command line? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Sorry for posting it here, but Google does a very bad job when searching for symbols.
What does the "|" mean in:
"some string" | someexecutable.py
It is the pipe symbol. It separates two programs on a command line (see Pipelines in the bash manual), and the standard output of the first program (on the LHS of the pipe) is connected to the standard input of the second program (on the RHS of the pipe).
For example:
who | wc -l
gives you a count of the number of people or sessions connected to your computer (plus one for the header line from who). To discount the header line:
who | sed 1d | wc -l
The input to sed comes from who, and the output of sed goes to wc.
The underlying system call is pipe(2) used in conjunction with fork(), dup2() and the exec*() system calls.
It's called pipe. It gives the stdout of the first command ("some string") as the stdin to the second command (someexecutable.py).
| is a pipe. It sends output of one command as input of the next. It is explained here http://www.ibm.com/developerworks/linux/library/l-lpic1-v3-103-4/#3-pipes

Resources