What am I missing?

2007-09-02 Thread abi

Hi,

I am having trouble running a command in a shell script that runs without
a problem on the command line. Consider the following script:



#!/bin/bash

entry="/cygdrive/c/Documents\ and\ Settings/arroyoa/Desktop"
exclude="-wholename '/cygdrive/c/Documents and
Settings/arroyoa/Desktop/asdf' -prune -o"

#find "/cygdrive/c/Documents and Settings/arroyoa/Desktop/" -wholename
'/cygdrive/c/Documents and Settings/arroyoa/Desktop/asdf' -prune -o -print

   OFS="${IFS}"
   IFS=$'\n'

echo "find "$entry" $exclude -print"
for j in `find "$entry" $exclude -print`; do
   echo "$j"
done



If you run the script above you will find the following output:

find /cygdrive/c/Documents\ and\ Settings/arroyoa/Desktop -wholename
'/cygdrive/c/Documents and Settings/arroyoa/Desktop/asdf' -prune -o -print
find: unknown predicate `-wholename '/cygdrive/c/Documents and
Settings/arroyoa/Desktop/asdf' -prune -o'

Then if you copy the command that was echoed and run it (find
/cygdrive/c/Documents\ and\ Settings/arroyoa/Desktop -wholename
'/cygdrive/c/Documents and Settings/arroyoa/Desktop/asdf' -prune -o
-print) then you no longer receive the error. What am I missing from the
script so that I can exclude these directories?

Thanks,
Abi





Re: What am I missing?

2007-09-02 Thread abi

I recently submitted this e-mail but found that by using the eval command,
and adding a slash (\) before the quotation mark fixed everything.
Disregard the question below.

>
> Hi,
>
> I am having trouble running a command in a shell script that runs without
> a problem on the command line. Consider the following script:
>
> 
>
> #!/bin/bash
>
> entry="/cygdrive/c/Documents\ and\ Settings/arroyoa/Desktop"
> exclude="-wholename '/cygdrive/c/Documents and
> Settings/arroyoa/Desktop/asdf' -prune -o"
>
> #find "/cygdrive/c/Documents and Settings/arroyoa/Desktop/" -wholename
> '/cygdrive/c/Documents and Settings/arroyoa/Desktop/asdf' -prune -o -print
>
>OFS="${IFS}"
>IFS=$'\n'
>
> echo "find "$entry" $exclude -print"
> for j in `find "$entry" $exclude -print`; do
>echo "$j"
> done
>
> 
>
> If you run the script above you will find the following output:
>
> find /cygdrive/c/Documents\ and\ Settings/arroyoa/Desktop -wholename
> '/cygdrive/c/Documents and Settings/arroyoa/Desktop/asdf' -prune -o -print
> find: unknown predicate `-wholename '/cygdrive/c/Documents and
> Settings/arroyoa/Desktop/asdf' -prune -o'
>
> Then if you copy the command that was echoed and run it (find
> /cygdrive/c/Documents\ and\ Settings/arroyoa/Desktop -wholename
> '/cygdrive/c/Documents and Settings/arroyoa/Desktop/asdf' -prune -o
> -print) then you no longer receive the error. What am I missing from the
> script so that I can exclude these directories?
>
> Thanks,
> Abi
>
>





Re: Readline history and bash's read -e

2007-09-02 Thread Chris F.A. Johnson
On 2007-08-31, Phil Endecott wrote:
> Dear Bash and Readline Experts,
>
> I have a simple shell script that reads user commands in a loop using
> "read -e".  -e enables readline, but not its history feature.  Is there
> any way to get readline history with bash's read builtin?
>
> I wouldn't want to get the user's regular bash history; rather, this
> program would need its own history file in the user's home directory.
> For example:
>
> read -e --historyfile=~/.myprogname_history CMD

history -r ~/.myprogname_history
read -ep ">> " CMD


-- 
   Chris F.A. Johnson  
   ===
   Author:
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
.




Re: Readline history and bash's read -e

2007-09-02 Thread Mike Stroyan
On Sat, Sep 01, 2007 at 12:11:58AM +0100, Phil Endecott wrote:
> Dear Bash and Readline Experts,
> 
> I have a simple shell script that reads user commands in a loop using
> "read -e".  -e enables readline, but not its history feature.  Is there
> any way to get readline history with bash's read builtin?

Phil,

  You can use "history -r" to read a file into the shell's history
and "history -s" to add each line that you read into the history.
Then use history -w to save the history back to the file.  Here is
an example with vi style readline editing.

#!/bin/bash
history -r script_history
set -o vi
CMD=""
while true
do
echo "Type something"
read -e CMD
history -s "$CMD"
echo "You typed $CMD"
case "$CMD" in
stop)
break
;;
history)
history
;;
esac
done
history -w script_history
echo stopping

-- 
Mike Stroyan <[EMAIL PROTECTED]>




Re: Readline history and bash's read -e

2007-09-02 Thread Chet Ramey
Phil Endecott wrote:
> Dear Bash and Readline Experts,
> 
> I have a simple shell script that reads user commands in a loop using
> "read -e".  -e enables readline, but not its history feature.  Is there
> any way to get readline history with bash's read builtin?

Sure.  You can do it entirely with bash builtins and shell variables.

> I wouldn't want to get the user's regular bash history; rather, this
> program would need its own history file in the user's home directory.
> For example:
> 
> read -e --historyfile=~/.myprogname_history CMD

HISTFILE=~/.myprogram_history
history -r

(The `history -r' is needed if you'd like history to persist across
program invocations.)

To save the lines read to the history list, use `history -s':

read -e CMD
[ -n "$CMD" ] && history -s "$CMD"

If at the end of the script you'd like to save the history to the
history file, use `history -w' or `history -a'.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
   Live Strong.  No day but today.
Chet Ramey, ITS, CWRU[EMAIL PROTECTED]http://cnswww.cns.cwru.edu/~chet/