Xray-core icon indicating copy to clipboard operation
Xray-core copied to clipboard

多文件配置时提示:-bash: syntax error near unexpected token `do'

Open PunkFleet opened this issue 2 years ago • 7 comments
trafficstars

sudo for BASE in 00_log 01_api 02_dns 03_routing 04_policy 05_outbounds 06_transport 07_stats 08_reverse vmess; do echo '{}' > "/usr/local/etc/xray/confs/$BASE.json"; done
-bash: syntax error near unexpected token `do'

文件名检查过没有错误,路径也正确,路径权限是777,请问这是哪里出问题了

PunkFleet avatar Nov 10 '23 04:11 PunkFleet

do后面的命令都是复制粘贴的,应该不会出错啊 https://xtls.github.io/config/features/multiple.html#%E6%8E%A8%E8%8D%90%E7%9A%84%E5%A4%9A%E6%96%87%E4%BB%B6%E5%88%97%E8%A1%A8

PunkFleet avatar Nov 10 '23 04:11 PunkFleet

sudo后面只能跟一条命令,分号是把多条命令写在一行,但还是多条命令。建议花点时间学下bash物有所值。

yomnxkcs avatar Nov 11 '23 06:11 yomnxkcs

如果支持文件夹形式引入那就更友好了。自动搜索文件夹下的 *.json; *.jsonx; *.yaml

BI7PRK avatar Nov 11 '23 12:11 BI7PRK

xray help run
usage: xray run [-c config.json] [-confdir dir]

Run Xray with config, the default command.

The -config=file, -c=file flags set the config files for
Xray. Multiple assign is accepted.

The -confdir=dir flag sets a dir with multiple json config

The -format=json flag sets the format of config files.
Default "auto".

The -test flag tells Xray to test config files only,
without launching the server

xray有文件夹加载,请自行修改systemctl托管的xray服务

zxbiao avatar Nov 11 '23 17:11 zxbiao

The issue in the command you've provided lies in the echo '{}' > "/usr/local/etc/xray/confs/$BASE.json" part. The command is trying to create a series of empty JSON files using a for loop, but it's encountering a syntax error due to the incorrect use of curly braces {}. In Bash, {} is used for brace expansion or as part of a command block, but not in this context.

To resolve this, you should replace {} with the correct content you want to echo into the files, or simply use "" (empty quotes) if you want to create empty files. The corrected command should look like this:

sudo for BASE in 00_log 01_api 02_dns 03_routing 04_policy 05_outbounds 06_transport 07_stats 08_reverse vmess; do echo "" > "/usr/local/etc/xray/confs/$BASE.json"; done

This command will create empty .json files for each item in the list. If you intended to put specific content into each file, you need to modify the echo command accordingly.

us254 avatar Nov 12 '23 18:11 us254

The issue in the command you've provided lies in the echo '{}' > "/usr/local/etc/xray/confs/$BASE.json" part. The command is trying to create a series of empty JSON files using a for loop, but it's encountering a syntax error due to the incorrect use of curly braces {}. In Bash, {} is used for brace expansion or as part of a command block, but not in this context.

To resolve this, you should replace {} with the correct content you want to echo into the files, or simply use "" (empty quotes) if you want to create empty files. The corrected command should look like this:

sudo for BASE in 00_log 01_api 02_dns 03_routing 04_policy 05_outbounds 06_transport 07_stats 08_reverse vmess; do echo "" > "/usr/local/etc/xray/confs/$BASE.json"; done

This command will create empty .json files for each item in the list. If you intended to put specific content into each file, you need to modify the echo command accordingly.

I'm guessing it's not due to that. I tried but it still doesn't work. But when I switch to sudo -s, the original command works and changes the contents of each file to {}

PunkFleet avatar Nov 13 '23 02:11 PunkFleet

如果支持文件夹形式引入那就更友好了。自动搜索文件夹下的 *.json; *.jsonx; *.yaml

一直都支持文件夹的好不好。这是我的文件夹: image

harvey-git avatar Jan 05 '24 10:01 harvey-git