简体   繁体   中英

Rename output of Shell script(s)

I am trying to create a script that runs an another script and changes the name from the output.

Here is the script so far:

#! /bin/bash

i=1

for N in mediainput.iso mediainput2.iso
do
    x264transcode $N
    mv $N $((i++))
done

This don`t that well. It just moves the files and renames them.

I need to first run the x264transcode and then rename the output of that. Since they all get the same name when x264transcode as processed the files.

Its okey that the name the files are changed to are 1 then 2 and so on.

But it would be a plus if there where a method of getting the name of the folder the file was inside or the file itself. Maybe choosing between them for different scenarios.

Example below:

  1. ~/Videos/Summer Vacation 2009/dvd.iso
  2. Output from x264: VIDEO01.mkv
  3. Output from rename script: Summer-Vacation-2009.mkv

Does x264transcode always call its output VIDEO01.mkv? Are all the video files dvd.iso? If so, something like this, to also get the correct filename with hyphens:

cd ~/Videos
for I in */dvd.iso
do
  x264transcode $I
  mv VIDEO01.mkv `dirname $I|tr ' ' -`.mkv
end

This is assuming x264transcode stores VIDEO01.mkv in the current directory rather than the directory its input file is located in.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM