我试图创建一个文件层次结构来存储数据。我想为每个数据采集会话创建一个文件夹。该文件夹有五个子文件夹,命名如下。下面的代码尝试给出了一个错误,但我不确定如何更正它。
代码
#!/bin/sh
TRACES = "/Traces"
LFPS = '/LFPS'
ANALYSIS = '/Analysis'
NOTES = '/Notes'
SPIKES = '/Spikes'
folders=($TRACES $LFPS $ANALYSIS $NOTES $SPIKES)
for folder in "${folders[@]}"
do
mkdir $folder
done
错误
声明变量时出错。如上所述,
bash
将翻转错误Command not found
。相反,如果我声明文件名为TRACES = $('\Traces')
,bash
则会翻转错误No such file or directory
。 最佳答案
删除变量名和值之间的空格:
#!/bin/sh
TRACES="/Traces"
LFPS='/LFPS'
ANALYSIS='/Analysis'
NOTES='/Notes'
SPIKES='/Spikes'
folders=($TRACES $LFPS $ANALYSIS $NOTES $SPIKES)
for folder in "${folders[@]}"
do
mkdir $folder
done
使用空格,
bash
将其解释为COMMAND param1 param2
用
=
作为param1