0

I am running my bash script with a file as the input file:

./myscript.sh anyfilename.txt

and then here is the script:

#!/bin/bash

input_file=$1
dest_dir="./destination"
mkdir -p "$dest_dir"
cp "$input_file" "$dest_dir"

when I run it, it copies the file to the destination directory using the same name as it is passed to the bash parameter, anyfilename.txt.

Question:

how can I copy the input file into the destination directory by renaming it always as myfile.txt?

1 Answer 1

2

You can use command like:

#!/bin/bash
input_file=$1
new_file=$2
dest_dir="./destination"
mkdir -p "$dest_dir"
cp "$input_file" "${dest_dir}/${new_file}"

and run the script like:

./myscript.sh anyfilename.txt myfile.txt

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.