How to pass a path as argument to shell script and copy a file from the path

廉价感情. 提交于 2019-12-08 13:40:54

问题


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

来源:https://stackoverflow.com/questions/24291992/how-to-pass-a-path-as-argument-to-shell-script-and-copy-a-file-from-the-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!