Sending output to Bash Script

There are many ways to send or receive data from embedded code. Other language-embedded code can send data to Bash using piping, saving, writing, or printing. Other language-embedded code can receive data through variables, files, user input, or pipes.

The following is an example of other language code sending output to Bash using pipe:

    ksh -c "ls" | cat > ./save_to_file
  

In the preceding command, ksh is sending directory content to bash by pipe, which will be stored in the file.

We can eliminate the use of pipe from the preceding example as follows:

    ksh -c "ls" > ./save_to_file
  

As we have eliminated the use of pipe, the preceding command has become more efficient. It is better to eliminate the middleman if ...

Get Learning Linux Shell Scripting - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.