For loop is not working with expect in pgp encyption script.

=========

-bash-4.1$ more TestScriptPGP.sh

!/bin/bash
!/usr/bin/expect -f

for i in ls *.txt
do
spawn /opt/PGP/pgp -e +force $i "<abc@gmail.com>"
expect "Are you sure you want to use"
send "y\n"
expect "$"
done;
-bash-4.1$ ./TestScriptPGP.sh
./TestScriptPGP.sh: line 5: spawn: command not found
couldn't read file "Are you sure you want to use": no such file or directory
./TestScriptPGP.sh: line 7: send: command not found
couldn't read file "$": no such file or directory
./TestScriptPGP.sh: line 5: spawn: command not found
couldn't read file "Are you sure you want to use": no such file or directory
./TestScriptPGP.sh: line 7: send: command not found
couldn't read file "$": no such file or directory
./TestScriptPGP.sh: line 5: spawn: command not found
couldn't read file "Are you sure you want to use": no such file or directory
./TestScriptPGP.sh: line 7: send: command not found
couldn't read file "$": no such file or directory
./TestScriptPGP.sh: line 5: spawn: command not found
couldn't read file "Are you sure you want to use": no such file or directory
./TestScriptPGP.sh: line 7: send: command not found
couldn't read file "$": no such file or directory
-bash-4.1$

=================

Recommended Answers

All 2 Replies

Hello,

Seen this many times before and used to drive me crazy, the ls command is aliased to ls --color and the escape codes are showing up as part of the file names. Try using /bin/ls and you should be fine.

Better still, don't try to parse the output of ls. Just do

for i in *.txt

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.