salt icon indicating copy to clipboard operation
salt copied to clipboard

[BUG]when run cmd.script with args=0 the script could not receive args

Open CyaLiven opened this issue 1 year ago • 1 comments

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

CyaLiven avatar Feb 27 '24 05:02 CyaLiven

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:

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!

welcome[bot] avatar Feb 27 '24 05:02 welcome[bot]

Validated the bug and I am seeing the same issue. Working on a fix now.

Akm0d avatar Jul 16 '24 17:07 Akm0d

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.

Akm0d avatar Jul 16 '24 18:07 Akm0d

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.

Akm0d avatar Jul 16 '24 18:07 Akm0d