0

I have some folders:

oldA with A_1.aaa, A_2.aaa, A_1.bbb, A.def, A.ghi 
oldB with B_1.aaa, B_2.aaa, B_1.bbb, B.def, B.ghi
and so on

and need to copy them to another folder with selection.

I want only A.def and A.ghi copy to /newA, so do with B. I have written a script but it doesn't work.

for i in A B C D
do
  folder="new${i}"
  mkdir $folder;
  cp path/to/old${i}/${i}{.def,.ghi} $folder
  cd $folder; some commands
  cd ..
done

The error is cp: cannot stat ‘oldA/A{.def,.ghi}’: No such file or directory

However, when I use direct command cp path/to/oldA/A{.def,.ghi} newA, it works well. What should I do?

If I want to copy only A_1.aaa and A_2.aaa, will the procedure be similar?

This is my actually script.

#!/bin/bash
folder="Disperse"
mkdir $folder
cp 3B7V.pdb $folder
cd $folder

#awk '$5 != "C"' 3B7V.pdb > 3B7V_temp.pdb
#awk '$4 != "C"' 3B7V_temp.pdb > AB.pdb
sed -n 403,1981p 3B7V.pdb > A.pdb
sed -n 1982,3586p 3B7V.pdb > B.pdb

cd ..;mkdir EM;cd EM
for i in A B
do 
  folder="${i}_EM"
  mkdir $folder
  cp ../em.mdp ../Disperse/${i}.pdb $folder
  cd $folder

  echo -e "\n4" | pdb2gmx -f ${i}.pdb -o ${i}.gro -water none
  grompp -f em.mdp -c ${i}.gro -p topol.top -o ${i}_em.tpr
  mdrun -v -deffnm ${i}_em
  #grompp -f em.mdp -c ${i}_em.gro -p topol.top -o ${i}_em_mead.tpr
  cd .. #at EM folder
done

cd ..;mkdir PQR;cd PQR
for i in A B
do
  folder="${i}_PQR"
  mkdir $folder
  cp ../EM/${i}_EM/${i}* $folder
  cd $folder

  editconf -f ${i}_em.gro -o ${i}_em.pdb
  awk '$1 != "REMARK"' ${i}_em.pdb > ${i}_temp.pdb
  pdb2pqr --ff=AMBER --apbs-input ${i}_temp.pdb ${i}.pqr -v > log_${i}
  #editconf -f ${i}_em_mead.tpr -mead ${i}_gro.pqr
  #for j in *.pqr; do sed 1,8d "$j" > ../"${j/.*}"_sed.pqr; done
  cd .. #at PQR folder
done

cd ..;mkdir APBS;cd APBS
for i in A B
do
  folder="${i}_APBS"
  mkdir $folder;ls
  cp ../PQR/${i}_PQR/${i}{.pqr,.in} $folder
  cd $folder

  abps ${i}.in
  cd .. #at APBS folder
done

Also, I have another problem in Konsole. I don't know whether it is relevant or not but I will post here too.

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Ooker
  • 647
  • 1
  • 8
  • 21
  • 1
    Is that `bash` with brace expansion enabled? What is the output of `echo $SHELL; echo $-`? It should work your way. Indenpendent of your problem: You should use `mkdir -p "$folder"`, `cp "path/to/old${i}/${i}"{.def,.ghi} "$folder"`, and `cd "$folder"`. – Hauke Laging May 21 '14 at 18:02
  • The outputs are `/bin/bash` and `himBH`. Your commands don't work. I think adding quotation marks don't make any changes. – Ooker May 21 '14 at 18:14
  • 1
    I told you in advance that these suggestions will not solve the problem. What is the shebang line of the script, `#!/bin/bash`? Have you executed `echo $SHELL; echo $-` in the script or in the shell which called the script? I suggest to reduce the code for approaching the problem. Put this single line in another script: `i=A; echo "path/to/old${i}/${i}"{.def,.ghi}` What is the output? – Hauke Laging May 21 '14 at 18:23
  • Yes, of course I have `#!/bin/bash` in top of the script. I executed on the shell called the script. When add to the old script, only `/bin/bash/` appears, the line for `echo $-` is blank. The output of the new script is `path/to/oldA/A"{.def,.ghi}` – Ooker May 21 '14 at 18:35
  • That is really interesting. Please put `set -B; echo $-` before the `i=A; echo "path/to/old${i}/${i}"{.def,.ghi}` line and run the script again. – Hauke Laging May 21 '14 at 18:45
  • The output has one line: `ttt: 2: set: Illegal option -B`. By interesting, do you mean that this is weird? :-s – Ooker May 21 '14 at 18:50
  • Now it is really weird. `-B` really should **not** be an illegal option to `bash`'s `set`. And it isn't here. What `bash` version do you use? `bash --version` I can imagine that something disables shell features for scripts (i.e. non-interactive shells) but that `set` options don't work (even though active in the calling shell!) seems kind of crazy to me. – Hauke Laging May 21 '14 at 18:58
  • Also try `file /bin/bash` it may be symlinked to another shell's executable (though I can't think of a why...) – Joseph R. May 21 '14 at 20:16
  • Post the complete script. – Gilles 'SO- stop being evil' May 21 '14 at 23:58
  • @HaukeLaging: version 4.2.45(1)-release (i686-pc-linux-gnu) – Ooker May 22 '14 at 00:07
  • @JosephR.: /bin/bash: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0x14661e2aea339b7fad80c1864a8a508890d6bb08, stripped – Ooker May 22 '14 at 00:07
  • @Gilles: I have posted it. Please come and see. – Ooker May 22 '14 at 00:12
  • No, post the COMPLETE script. No just part of it. – Gilles 'SO- stop being evil' May 22 '14 at 00:18
  • @Gilles The rest of the script seems not to be the problem. See the comments above. The problem occurs even in an "empty" script. – Hauke Laging May 22 '14 at 00:21
  • @HaukeLaging The error `cp: cannot stat ‘A_old/A{.pqr,.in}’: No such file or directory` occurs even with an empty script? That would be really strange, but I don't see that in the comments. – Gilles 'SO- stop being evil' May 22 '14 at 00:24
  • @Gilles The `cp` error is obviously not the interesting point. The interesting point is that brace expansion is disabled (and cannot be enabled). In comment #3 I asked the OP to create a new script which just checks that. My understanding of comment #4 is that the brace expansion problem arises there, too. – Hauke Laging May 22 '14 at 00:29
  • @Gilles: well, if you want: http://pastebin.com/raw.php?i=ZJRA7qUz – Ooker May 22 '14 at 00:30
  • Oops, I mean the error is `cp: cannot stat ‘oldA/A{.def,.ghi}’: No such file or directory` in the sense of the example. I am going to edit it. – Ooker May 22 '14 at 00:36
  • I have found the answer. Please check if it's right. – Ooker May 23 '14 at 18:20

1 Answers1

0

It turns out that I use $ sh script to run the scrip, not $ bash script. The brace expansion requires bash to run.

Ooker
  • 647
  • 1
  • 8
  • 21