-2

I want to write a shell script in Linux, that will run the command wpaclean (usage: wpaclean <out.cap> <in.cap> ) and take every file in the current working directory as an argument.

For example, my shell script starts like this:

#! /bin/sh
cd /testfolder/

inside the folder there are numerous files: A.cap B.cap C.cap D.cap and so forth

Which commands do i need to put in the shell script, such that it automatically runs the command for every file in the directory and also automatically renames it?

  • 1
    `for file in *.cap` – Barmar Oct 20 '20 at 00:24
  • 1
    `for $file in *.cap ; do SpecialCapCmd "$file" ; done` Now do research about the *nix utility `mv`. To read a help page about it, try `man mv` or `info mv`, else search the internet with `unix mv usage`. If you search here with `[linux] mv usage`, you'll find 90+ Q/A. Good luck. – shellter Oct 20 '20 at 00:31

1 Answers1

0
#!/usr/bin/env bash

for i in ./*.cap;do
    wpaclean "${i}" "${i%.*}-new.cap"
    mv "${i}" "${i%.*}"-old.cap
    echo "done with ${i}"
done

${var%.*} is a parameter expansion .

nacn
  • 25
  • 4