0

I am trying to set environment variable in virtual machine using custom extension but i am not able to do so.

I created a script.sh file with following content

#!/bin/bash

if [ -z "$hiddencode" ]
then
    echo "Setting user information"
    echo "export hiddencode=213452314">>~/.profile
    echo "export hiddencode=213452314">>~/.bashrc
    . ~/.bashrc
    . ~/.profile

else
      echo "information is already present"
fi
exit

The deployment itself fails saying cannot create ~/.profile: Directory nonexistent

The command used to run script is "sh script.sh"

How do I set environment variable using custom extension for linux in azure

Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

0

Assuming you are running this scrip with sudo you should be able to use:

sh -c 'echo "text" >> file'

like so:

#!/bin/bash

if [ -z "$hiddencode" ]
then
    echo "Setting user information"
    sh -c 'echo "export hiddencode=213452314">>~/.profile'
    sh -c 'echo "export hiddencode=213452314">>~/.bashrc'
    . ~/.bashrc
    . ~/.profile

else
      echo "information is already present"
fi
exit
vk86
  • 51
  • 6