# Creating Cmds with variable number of args

**URL:** https://discourse.julialang.org/t/creating-cmds-with-variable-number-of-args/96397
**Category:** General Usage
**Created:** [March 21, 2023, 3:04pm UTC](https://discourse.julialang.org/t/creating-cmds-with-variable-number-of-args/96397 "2023-03-21T15:04:47Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Conrad\_Wiebe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/conrad_wiebe/32/47934_2.png) [@Conrad\_Wiebe](https://discourse.julialang.org/u/Conrad_Wiebe)
#### Post date: [March 21, 2023, 3:04pm UTC](https://discourse.julialang.org/t/creating-cmds-with-variable-number-of-args/96397/1 "2023-03-21T15:04:47Z")

</div>

I’m trying to create a scp command to copy over a variable number of files to another computer. I’d like for it to be a single scp call rather than one per file as it is much more efficient. I have something looking like this:

```julia
function CreateStagingCommand(ip_addr::AbstractString, operations::Vector{ProcessReplacement})
	files = ""
	for replacement in operations
		# Add the file-path to the list of things to copy
		files *= "$(replacement.replacement_location) "
	end
	command = `scp -i "~"/real/file/path/here/id_rsa $(files) root@$(ip_addr):$(staging_area)`
	return command
end

```

Problem is, Julia sees the $(files) as a single parameter with spaces in it and (not so) helpfully puts quotes around. It’s possible to do something like:

```julia
function CreateStagingCommand(ip_addr::AbstractString, operations::Vector{ProcessReplacement})
	files = ""
	for replacement in operations
		# Add the file-path to the list of things to copy
		files *= "$(replacement.replacement_location) "
	end
	command = `scp -i "~"/real/file/path/here/id_rsa $(a)$(b)$(c)$(d)$(etc) root@$(ip_addr):$(staging_area)`
	return command
end

```

but that means I have to be aware of the max number of files a user is going to copy ahead of time, and also makes the code much uglier to read and maintain.

Anyone have a good way to handle this?

---

<div class="post-metadata">

### Author: ![maleadt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maleadt/32/10097_2.png) [@maleadt](https://discourse.julialang.org/u/maleadt)
#### Post date: [March 21, 2023, 3:09pm UTC](https://discourse.julialang.org/t/creating-cmds-with-variable-number-of-args/96397/2 "2023-03-21T15:09:58Z")

</div>

You can interpolate `Cmd` objects:

```julia
julia> cmd = `echo`
`echo`

julia> for i in 1:10
           cmd = `$cmd $i`
       end

julia> run(cmd)
1 2 3 4 5 6 7 8 9 10

```

---

<div class="post-metadata">

### Author: ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)
#### Post date: [March 21, 2023, 3:12pm UTC](https://discourse.julialang.org/t/creating-cmds-with-variable-number-of-args/96397/3 "2023-03-21T15:12:41Z")

</div>

Just interpolate an array of filenames.

```julia
julia> files = ["README", "default_par.yaml"]
2-element Vector{String}:
 "README"
 "default_par.yaml"

julia> run(`ls -l $files`)
-rw-rw-r-- 1 gunnar gunnar 1325 mar 21 13:32 default_par.yaml
-rw-rw-r-- 1 gunnar gunnar 126 mar 21 13:32 README

```
