2016-09-16 98 views
0

我试图通过'运行Shell脚本'通过参数发送一个curl命令,但没有运气。我使用/ bin/bash并将info作为参数传递。这里是我的脚本,但从IFTTT不断得到Bad Request。我得到这是不正确使用参数(如果我只是把"value1":"test"它工作正常),我应该如何格式化$ 1?在Automator中运行带有参数的运行Shell脚本中的卷曲

for f 
do 
    curl -X POST -H "Content-Type: application/json" -d '{"value1":$1}' https://maker.ifttt.com/trigger/Automator/with/key/heremykey 
done 

谢谢!

回答

2

您应该传递有效的JSON。有没有内置在猛砸JSON支持,所以你需要使用外部工具,如PHP,或节点:

#!/bin/bash - 

function json_encode { 
    printf "$1" | php -r 'echo json_encode(stream_get_contents(STDIN));' 
} 

for f 
do 
    value=`json_encode "$f"` 
    curl -X POST -H "Content-Type: application/json" -d "{\"value1\":$value}" \ 
    https://maker.ifttt.com/trigger/Automator/with/key/heremykey 
done 

的脚本应该发送{"value1": ...}字符串中的每一项[email protected](因为短for循环的版本在[email protected]上运行)。

+0

非常好,谢谢!当我们处理它时,从$ /文件夹/子文件夹/子文件夹/ etc/etc/file.mp4到#file.mp4解析$ 1的最佳方法是什么? –

+1

@PJPalomaki'basename“$ 1”' –