0

On the following Powershell script:

$Project_number = Read-Host -Prompt 'Input your Project Name ie. 02XXX'
$Project_code = Read-Host -Prompt 'Input your Project Code in capita letters ie. CRE'

plink -load profile1 -batch 'setfacl -Rm d:g:user1:rwX,g:user1:rwX "/FILES/projects/$Project_number $Project_code" && find "/FILES/projects/$Project_number $Project_code" -maxdepth 1 -exec setfacl -m d:g:user1:r-X,g:user1:r-X {} \;'

How can I make plink (connected via SSH to a Linux fileserver) expand the variables $Project_number and $Project_code within the plink command.

At the moment they don't and I receive an error:

plink : setfacl: /FILES/projects/ : No such file or directory

If I type them manually, it will work, therefore it has to be with my syntax.

Thanks

pakyrs
  • 37
  • 1
  • 4
  • 1
    If you're running this from powershell, you need to swap the single quotes with double quotes, and then escape the double quotes inside. Single quotes read text as-is, so literally. Say we have a variable of: `$Var = 'text'`. If we wrap the variable in single quotes you get: `'$Var'; $Var`, vs double quotes: `"$Var"; text`. Double quotes allow you to expand a variable, where as single quotes read text literally. – Abraham Zinala Aug 01 '21 at 13:09

2 Answers2

1

I see that the below link has spaces between $Project_number & $Project_code

plink -load profile1 -batch 'setfacl -Rm d:g:user1:rwX,g:user1:rwX "/FILES/projects/$Project_number $Project_code" && find "/FILES/projects/$Project_number $Project_code" -maxdepth 1 -exec setfacl -m d:g:user1:r-X,g:user1:r-X {} \;'

Have you tried without those spaces ?

Vishal Bakshi
  • 101
  • 1
  • 7
0

Thanks I was able to figure it out, just needed to use double quotes, remove the quotes on the path of setfacl and escape the space. Like so:

plink -load profile1 -batch "setfacl -Rm d:g:user1:rwX,g:user1:rwX /FILES/projects/$Project_number\ $Project_code && find /FILES/projects/$Project_number\ $Project_code -maxdepth 1 -exec setfacl -m d:g:user1:r-X,g:user1:r-X {} \;"
pakyrs
  • 37
  • 1
  • 4