How reference a filename or path with spaces in a

2019-08-07 03:44发布

I'm trying to write a simple shell script, but am struggling to figure out why I can't keep spaces in a string variable that I use to produce file names in a shell script.

#!/bin/bash

let minus3=10#$(date +%Y)-3
let minus2=10#$(date +%Y)-2
string="$minus3 - $minus2"
dir="'$minus3\ -\ $minus2'"
printf "\nIt is $(date +%Y).\nWe will be moving files from $string today.\n\n"

The ONLY CORRECTLY working command:

mkdir $minus3\ -\ $minus2

The commands that produce multiple incorrectly names directories because of the space:

mkdir $dir
mkdir $string```

0条回答
登录 后发表回答