简体   繁体   中英

how to change string in shell (and copy file-script)

I usually work with bash, and I know how to do it there

but this script must be added to a

#!/bin/sh

file

Here is what I need to do: in $1 I get a string like "../blo/thisRun.senerio"

I want to copy a file to a dir with "thisRun" name (thisRun extracted from $1), so i try

cp ../../files/customSettings.ini ../logs/thisRun

where "thisRun" is from the $1 input

1) how to get thisRun from thisRun.senerio in sh

2) how to write this script in sh and not bash?

You will be writing in some version of sh thanks to the shebang. Try the following:

newdir=$(basename "$1" | cut -d. -f1)
if [ -d ../logs/${newdir} ]; then
   cp ../../files/customSettings.ini ../logs/${newdir}
else
   echo I do not want to mkdir -p ../logs/${newdir}, maybe something wrong with script
   exit 1
fi

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