Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #212681

Re: Strange Bash Script Problem

From Greg Wooledge <wooledg@eeg.ccf.org>
Newsgroups linux.debian.user
Subject Re: Strange Bash Script Problem
Date 2019-08-12 15:40 +0200
Message-ID <yuiIh-4R4-3@gated-at.bofh.it> (permalink)
References <yu0BH-1NS-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Sun, Aug 11, 2019 at 02:10:06PM -0400, Stephen P. Molnar wrote:
> Thanks to all that shared their expertise.
> 
> #!/bin/bash
> while IFS= read -r d
> do
>     cd "${d}_apo-3k9b"
>     echo "${d}_apo-3k9b"
>     echo "${d}_apo-3k9b.dpf"
>     /home/comp/Apps/Autodock/autodock4 -p "${d}_apo-3k9b.dpf" -l
> "${d}_apo-3k9b.dlg"
>     cd ..
> done <ligand.list
> 
> and dos2unix solved the problem!!!!!!

There's still one more problem you want to fix: the exit status of cd
isn't being checked.  If the cd fails, your script still continues on
to run the two echo commands and the autodock4 command.  I don't know
what autodock4 does, but running it in the wrong directory is probably
not helpful.

Here's how I would solve that (there are other ways too):

#!/bin/bash
while IFS= read -r d
do
    ( cd "${d}_apo-3k9b" || exit
      echo "${d}_apo-3k9b"
      echo "${d}_apo-3k9b.dpf"
      exec /home/comp/Apps/Autodock/autodock4 -p "${d}_apo-3k9b.dpf" -l "${d}_apo-3k9b.dlg"
    )
done <ligand.list


P.S. it would also have been possible to work around the carriage return
issues with IFS, but your dos2unix approach is perfectly valid as well.

Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Strange Bash Script Problem "Stephen P. Molnar" <s.molnar@sbcglobal.net> - 2019-08-11 20:20 +0200
  Re: Strange Bash Script Problem Greg Wooledge <wooledg@eeg.ccf.org> - 2019-08-12 15:40 +0200
    Re: Strange Bash Script Problem "Stephen P. Molnar" <s.molnar@sbcglobal.net> - 2019-08-12 16:30 +0200
    Re: Strange Bash Script Problem Greg Wooledge <wooledg@eeg.ccf.org> - 2019-08-12 19:30 +0200
      Re: Strange Bash Script Problem Lee <ler762@gmail.com> - 2019-08-12 19:40 +0200
        Re: Strange Bash Script Problem Greg Wooledge <wooledg@eeg.ccf.org> - 2019-08-12 19:50 +0200
          Re: Strange Bash Script Problem Lee <ler762@gmail.com> - 2019-08-12 20:00 +0200
            Re: Strange Bash Script Problem Greg Wooledge <wooledg@eeg.ccf.org> - 2019-08-12 20:20 +0200
              Re: Strange Bash Script Problem Lee <ler762@gmail.com> - 2019-08-12 21:10 +0200
                Re: Strange Bash Script Problem David <bouncingcats@gmail.com> - 2019-08-13 02:00 +0200
    Re: Strange Bash Script Problem Lee <ler762@gmail.com> - 2019-08-12 19:30 +0200

csiph-web