Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Bash passing a variable to another script using a while loop vs an arg

16 views
Skip to first unread message

Chris Roberts

unread,
Mar 21, 2022, 2:08:38 PM3/21/22
to
########
Perhaps someone out there could assist?
I am having an issue using my script. It works fine when I feed it an inline argument, but NOT when I get the argument from a list and pass it as a variable.

WORKS: "Scriptname encr1": I put the filename to encrypt as an arg to this script.
It then passes to my expect script which encrypts just fine. (using openssl)
#FILENAME="${1%}"
#encrit.exp "$FILENAME" "$FILENAME.enc"

NOT WORKING:"enc2-lab" I read filename from a list using a while loop.
It then pass this to that same working expect encryption script.
But, in this case, it produces an empty zero byte filename.enc file.
#while read -r line;
#do
#encrit.exp "${line}" "${line}.enc"
----
WORKING:

Dell$ encr1 blah.pdf
USAGE: $>encr1 filename-to-encrypt
The filename to encrypt is "blah.pdf"
blah.pdf exists
spawn openssl enc -iter 1000 -salt -aes-256-cbc -in blah.pdf -out blah.pdf.enc
enter aes-256-cbc encryption password:
Verifying - enter aes-256-cbc encryption password:
ENCRYPTON PERFORMED! (blah.pdf.enc has been Created and is 75999 bytes)
-----
NOT WORKING: (scriptname enc2-lab): This script gathers the argument from a file and then uses it to run the above command.
#encrit.exp "$file" "$file.enc" #This way only works on the 1st loop, enc files are 0 bytes

The above command seems to process it, but then we end up with a zero byte empty file.?
Dell$ enc2-lab
--Current line is /mnt/c/TMP/blah.pdf ---
Line 1 is This is a file ( "/mnt/c/TMP/blah.pdf" )
ENCRYPTING FILE. /mnt/c/TMP/blah.pdf
spawn openssl enc -iter 1000 -salt -aes-256-cbc -in blah.pdf -out blah.pdf.enc
enter aes-256-cbc encryption password:
Verifying - enter aes-256-cbc encryption password:
ENCRYPTON PERFORMED! (blah.pdf.enc has been Created and is 0 bytes)

Note that the above output is a useless empty file.
----
thanks,
crzzy1
#########

Janis Papanagnou

unread,
Mar 21, 2022, 3:36:14 PM3/21/22
to
I suggest to try to post coherent code instead of the fragments of
the dis-functional trash we see below.

Why are all lines commented out with '#' ?
Why do you use the '%' in ${1%} ?
Why didn't you close the loop with 'done' ?
What is the called syntax you used ?

For a start you may call your script with the -x option, as in
sh -x your_script your_args
to see what's going on.

And reduce your scripts to the essentials before re-posting.

Good luck!

Ed Morton

unread,
Mar 21, 2022, 3:51:36 PM3/21/22
to
On 3/21/2022 1:08 PM, Chris Roberts wrote:
> ########
> Perhaps someone out there could assist?

Copy/paste your code into http://shellcheck.net, fix the issues it tells
you about, and then if you still have a problem post that corrected
script you want help with here.

Ed.

Chris Roberts

unread,
Mar 26, 2022, 12:58:02 PM3/26/22
to
I found out my issue.
There was no real error in the script.
It was working in a stand alone script, but NOT within a while loop.
I just had do add "sleep 1" after the command to give it time to process.

Thank you to all those who replied.


0 new messages