Can cmd echo take input from a file that is redirected to stdin? - echo

As we all know, if we type echo abc it will print abc to the terminal.
But what if we put abc to a file try and type echo < try?
I tried but it just printed an empty line.
$ echo < try
$

Related

echo shows command I want to execute

First let me explain that I have very little expertise with bash scripting. I only use it for very simple applications.
My script is used to generate a grep command.
I use the echo command as an interim debug tool. I figure that if I can get the echo command to show the command I want to execute, all I have to do is remove the echo and the quotes and the command inside the echo should do what I want.
Here is my script (called grepper3.sh). Again, I am not an expert at this:
#!/bin/bash
echo "what should I grep?"
read this
echo "grep -Ri \"$this\" > \"$this\""
Here is what happens when I execute:
master#master-Latitude-E6440:~$ ./grepper3.sh
what should I grep?
all that
grep -Ri "all that" > "all that"
The grep command being echoed by the code is exactly what I want. But when I remove the echo and the surrounding double quotes:
was: echo "grep -Ri \"$this\" > \"$this\""
changed to: grep -Ri \"$this\" > \"$this\"
I get this:
master#master-Latitude-E6440:~$ ./grepper3.sh
what should I grep?
all that
./grepper3.sh: line 5: \"$this\": ambiguous redirect
I'm guessing that there is a simple fix, but I can't figure it out.
You can add . to recursive search.
#!/bin/bash
echo "what should I grep?"
read this
grep -Ri $this > $this .
All you need to to is to change the quotation marks to backticks.
Your new code would be:
#!/bin/bash
echo "what should I grep?"
read this
echo `grep -Ri \"$this\" > \"$this\"`
Here is what I finally got to work. Thanks for all of your help!
#!/bin/bash
echo "what should I grep?"
read this
DEST="/home/master/results/$this"
grep -Ri "$this" > "$DEST"

What is the difference between cat < hello.txt and cat hello (the content of hello.txt is just hello)

I created a file echo hello > hello.txt and then executed cat < hello.txt which gives me "hello", I thought using < hello.txt would mean that the variable after cat would be the content of the file which is hello. However, when I execute cat hello it gives me an error because "cat" only deals with files. Can anyone help me understand why this is the case?

CQLSH: How to print text on execution of >source 'CommandFile';

I am using these functionalities:
Linux>cqlsh
cqlsh>use mydatabase;
cqlsh:mydatabase>source 'myCommands.cqlsh';
...
cqlsh:mydatabase>
Since I am executing a file, I wish to comment some outputs, I would like to find a way to print a sort of echo '' or print "hello"; on the output. Is it possible ?
You could just script this out, piping your split CQL scripts to cqlsh:
#!/bin/sh
echo "SOURCE 'myCommands1.cql'" | cqlsh
echo "hello"
echo "SOURCE 'myCommands2.cql'" | cqlsh
echo "done.."

send email from openVMS

I am not familiar with OpenVMS but I would like to understand how to write a script that will send an email whenever I call it. My understanding is that the body of the email is put in a temp file before it is converted to text and sent. How do I create this file? Do you have any examples to write a script that will send an email like this?
From: blah#gmail.com
To: you#gmail.com
Subject: this is a body
Body:
Line 1
Line 2
Line 3
Thank you in advance.
$ temp = f$unique() + ".tmp"
$ open/write/error=error temp 'temp'
$ write temp "line1"
$ write temp "line2"
$ write temp "line3"
$ close temp
$ define/user tcpip$smtp_from "blah#gmail.com"
$ mail/subject="this is a body" 'temp' "you#gmail.com"
$ delete/nolog 'temp';*
$ goto exit
$error:
$ write sys$output "Unexpected error: " + f$message ($status)
$ goto exit
$exit:
$ exit
You can send email from the command line:
$ mail/subject="this is a body" Sys$Input you#gmail.com
Line 1
Line 2
Line 3
$ exit
Normally you would create a file to send first:
$ create MyMessage.txt
Line 1
Line 2
Line 3
$ mail/subject="this is a body" MyMessage.txt you#gmail.com
$ delete MyMessage.txt;
Documentation is here.
The answer that I saw includes the files into your body.
You maybe want to join a file... Here's how I attach a file in email:
$ UUENCODE my_file_to_attach.ext my_file_to_attach.ext
$ MAIL/SUBJECT="A subject..." my_file_to_attach.ext you#a_domain.com
$ DELETE my_file_to_attach.ext;
If you want to include a body:
$ CREATE temp.file
Hello,
Here's the in attachment.
Regards.
$ UUENCODE my_file_to_attach.ext my_file_to_attach.ext
$ TYPE my_file_to_attach.ext, temp.file physical_file_send.txt
$ MAIL/SUBJECT="A subject" physical_file_send.txt you#a_domain.com
$ DELETE physical_file_send.txt;, my_file_to_attach.ext;

how to trim wipe output with sed?

i want to trim an output of wipe command with sed.
i try to use this one:
wipe -vx7 /dev/sdb 2>&1 | sed -u 's/.*\ \([0-9]\+\).*/\1/g'
but it don't work for some reason.
when i use echo & sed to print the output of wipe command it works!
echo "/dev/sdb: 10%" | sed -u 's/.*\ \([0-9]\+\).*/\1/g'
what i'm doing wrong?
Thanks!
That looks like a progress indicator. They are often output directly to the tty instead of to stdout or stderr. You may be able to use the expect script called unbuffer (source) or some other method to create a pseudo tty. Be aware that there will probably be more junk such as \r, etc., that you may need to filter out.
Demonstration:
$ cat foo
#!/bin/sh
echo hello > /dev/tty
$ a=$(./foo)
hello
$ echo $a
$ a=$(unbuffer ./foo)
$ echo $a
hello