How to pass a path as argument to shell script and

2019-06-08 17:10发布

问题:

I've written bash script to open a file passed as argument and write it into another file. But my script will work properly only if the file is in the current directory. Now i need to open and write the file that is not in the current directory also.

If compile is the name of my script, then ./compile next/123/file.txt should open the file.txt in the passed path. How can I do it?

#!/bin/sh
#FIRST SCRIPT
clear
echo "-----STARTING COMPILATION-----"
#echo $1
name=$1   # Copy the filename to name
find . -iname $name -maxdepth 1 -exec cp {} $name \;
new_file="tempwithfile.adb"
cp $name $new_file #copy the file to new_file

echo "compiling"
dir >filelist.txt
gcc writefile.c
run_file="run_file.txt"
echo $name > $run_file
./a.out
echo ""
echo "cleaning"
echo ""

make clean
make -f makefile
./semantizer -da <withfile.adb

Thankyou