小编and*_*ewz的帖子

分配给 bash 脚本中的变量

我有以下脚本,我尝试创建一个空文本文件。我试过touch,我试过echo -n >——他们都失败了。

#!/bin/bash

set filename_result="contents"

echo "filename=$filename_result" # Shows: filename=

rm -f "$filename_result".json

touch $filename_result # Error: usage: touch [-A [-][[hh]mm]SS] [-acfhm] [-r file] [-t [[CC]YY]MMDDhhmm[.SS]] file ...
# Note that `% touch myfile` works fine on the command line

touch -- "$filename_result" # Error: touch: : No such file or directory

echo -n > "$filename_result" # Error: No such file or directory

echo "[" >> "$filename_result"

for file in *json
do
    echo "examining file: …
Run Code Online (Sandbox Code Playgroud)

shell bash variable assignment

0
推荐指数
2
解决办法
1948
查看次数

标签 统计

assignment ×1

bash ×1

shell ×1

variable ×1