Search code examples
bashazureazure-pipelinesazure-cli

Paste Command removing input characters when spaces are present - Creating VariableGroups in Az pipelines


Summary: Trying to create an automated script to create variable groups based on an input list in a text file. Script works so far except for the entries that have spaces in them. (This is not under my control, I know I would never name anything with spaces, but what can I do?) For whatever reason, the paste command seems to be weirding out on the entries with spaces in them, or at least I think it is paste that is doing it given the result of the echo commands you see above. Am I missing something obvious? On a related note, in a similar script, it seemed to remove "/" symbols unless I doubled up on them like "//". What am I doing wrong?

#!/bin/bash

echo "Enter your PAT"
read PAT
echo "Project Name"
read ProjName

for VarGroup in LaunchPointVariableGroups.txt; do
    vfile="$(basename -- $VarGroup)"
    paste $vfile | while read groupname; do
      echo "$groupname" "groupname"
      echo $vfile "vfile"
      echo $VarGroup "VarGroup"
      echo $ProjName "ProjName"

      AZURE_DEVOPS_EXT_PAT=$PAT az pipelines variable-group create --name $groupname --description $groupname --variables a=a --project "$ProjName"
    done
done

Output is:

Examples from AI knowledge base: https://aka.ms/cli_ref Read more about the command in reference docs groupnamerod DiscoveryServices" VariableGroups.txt vfile VariableGroups.txt VarGroup DevOps Poc ProjName DEF Prod DiscoveryServices"Prod DiscoveryServices"

Examples from AI knowledge base: https://aka.ms/cli_ref Read more about the command in reference docs groupnamerod LMNOPConfig" VariableGroups.txt vfile VariableGroups.txt VarGroup DevOps Poc ProjName DEF Prod LMNOPConfig"s: DEF Prod LMNOPConfig"

On lines like: "ABC DEF Prod DiscoveryServices" and "ABC DEF Prod LMNOPConfig"


Solution

  • I discovered, by using shellCheck, that the errors were mostly due to not using -r flag with read commands which mangles backslashes and also not using double quotes which caused "globbing and splitting"