Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access environment variables in an Expect script?

I would like to access the PATH environment variable inside an expect script.

How can I achieve that ?

My actual script is :

#!/usr/bin/expect set timeout 300 send "echo $PATH\r" 

and its ouput is :

can't read "PATH": no such variable     while executing "send "echo $PATH\r"" 
like image 305
Xavier V. Avatar asked Oct 02 '12 17:10

Xavier V.


People also ask

How do I see my environment variables?

On the Windows taskbar, right-click the Windows icon and select System. In the Settings window, under Related Settings, click Advanced system settings. On the Advanced tab, click Environment Variables.

How do I read an environment variable in terminal?

To display the values of environment variables, use the printenv command. If you specify the Name parameter, the system only prints the value associated with the variable you requested.


2 Answers

Expect is an extension of Tcl. Tcl access enviroment variables via the global env array:

send_user "$env(PATH)\n" 
like image 72
glenn jackman Avatar answered Sep 21 '22 23:09

glenn jackman


You can use the global env array by using:

$::env(PATH)     

This notion will also work inside procedures.

like image 44
Timmah Avatar answered Sep 22 '22 23:09

Timmah