#!/bin/bash
file=debian.deb
test=basename $file .deb
DP="blah/blah/$test/$test.php"
read -p "[$DP]: " DPREPLY
DPREPLY=${DPREPLY:-$DP}
echo "Blah is set to $DPREPLY"
echo $DPREPLY>>testfile
So what I’m trying to do is set the variable test from the variable file and use it in the file testfile.
Use the command substitution
$(...)mechanism:You can also use backquotes, but these are not recommended in modern scripts (mainly because they don’t nest as well as the
$(...)notation).You need to know about backquotes in order to interpret other people’s scripts; you shouldn’t be using them in your own.
Note the use of quotes around
"$file"; this ensures that spaces in filenames are handled correctly.