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.

  • 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
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.