0

I would like to make a simple bash script where the goal is to make it run another script and move the output files from that script to a different folder.

The problem is , that this somescript.pl creates a file like this: customfile-Withcontent-202305231159.tar.gz

As you can see there is a fixated prefix customfile-Withcontent- but there is a suffix for the name with the actual date.

What I would like to achieve is to make a bash script, which some kind of autocompletes the actually created file, and moves it to the desired folder, somehow like this:

For example:

./somescript.py  #this script creates a file #first I create the file
mv customfile-Withcontent *pressing TAB or smth* so it completes the filename /Desiredfolder/Desiredfilename.tar.gz #moves the file with renaming.

The somescript.py is not editable, anyone has any suggestions?

I tried to edit the somescript.py but it made wrong everything, and it doesnt run so I think that wouldnt work. I would like to automate a work, there are 200 files to move.

Bodo
  • 9,287
  • 1
  • 13
  • 29
  • Welcome to Stack Overflow (SO). [SO is a question and answer page for professional and enthusiast programmers](https://stackoverflow.com/tour). Please add your own code to your question. You are expected to show at least the amount of research you have put into solving this question yourself. – Jetchisel May 23 '23 at 10:06
  • To me it is not fully clear what you want to achieve. Please [edit] your question and add more details. Do you want to move/rename about 200 existing files `customfile-Withcontent-202305231159.tar.gz` once? Do you want to rename every file just after it has been created by `somescript.py`? How do you determine the destination directory and file name for every existing file? Show an example of a few input files and the expected result. Can you show the contents of `somescript.py` and what you tried to change? – Bodo May 23 '23 at 10:42
  • When you talk about "pressing tab", that sounds like you're looking for an interactive process. We don't do that here -- our focus is on scripting. But if there's only one match, you can just use a glob or wildcard to find it. (If there's more than one match, you need to decide how you want the code to pick a specific one to use). – Charles Duffy May 23 '23 at 10:46
  • Essentially, though, what you're looking for is the same whether it's files or directories. I'm closing with a file-centric duplicate, but the same technique will work for a directory name. (That said, don't use any answer that tells you to run `ls -t` -- those answers are all buggy for the reasons given in [ParsingLs](https://mywiki.wooledge.org/ParsingLs); use the techniques given in [BashFAQ #3](https://mywiki.wooledge.org/BashFAQ/003) instead) – Charles Duffy May 23 '23 at 10:48
  • `mv customfile-Withcontent* /Desiredfolder/Desiredname.tar.gz` – Charles Duffy May 23 '23 at 10:50

0 Answers0