salt
salt copied to clipboard
[BUG]when run cmd.script with args=0 the script could not receive args
Description
foo.sh
#!/bin/sh
echo $*
when run salt myminion cmd.script salt://foo.sh 0 or salt myminion cmd.script salt://foo.sh "0", can't print 0 when run salt myminion cmd.script salt://foo.sh 1, can print 1 when run salt myminion cmd.script salt://foo.sh "'0'", can print 0
i found code in
[modulescmdmod.py](https://github.com/saltstack/salt/blob/master/salt/modules/cmdmod.py#L2918)
cmd_path + " " + str(args) if args else cmd_path
Hi there! Welcome to the Salt Community! Thank you for making your first contribution. We have a lengthy process for issues and PRs. Someone from the Core Team will follow up as soon as possible. In the meantime, here’s some information that may help as you continue your Salt journey. Please be sure to review our Code of Conduct. Also, check out some of our community resources including:
- Community Wiki
- Salt’s Contributor Guide
- Join our Community Slack
- IRC on LiberaChat
- Salt Project YouTube channel
- Salt Project Twitch channel
There are lots of ways to get involved in our community. Every month, there are around a dozen opportunities to meet with other contributors and the Salt Core team and collaborate in real time. The best way to keep track is by subscribing to the Salt Community Events Calendar. If you have additional questions, email us at [email protected]. We’re glad you’ve joined our community and look forward to doing awesome things with you!
Validated the bug and I am seeing the same issue. Working on a fix now.
Considering this script:
#!/bin/bash
echo $*
If I run it with cmd.script
like this:
$ salt-call --local cmd.script salt://foo.sh "0"
Then the zero does not even get passed to the script.
However, if I run it like this:
$ salt-call --local cmd.script salt://foo.sh "''0''"
Then the output is as expected.
Come to think of it, given how salt renders input to scripts and output from scripts -- this might just be a documentation issue. If you want to pass or return a falsey value (a string that evaluates to a false value in a python conditional) with "cmd.script", then you need to doubly quote it.