Find the answer to your Linux question:
Results 1 to 3 of 3
I suspect it is not possible, but just not sure why.. my PS1 is defined as my_login_name@hostname:current_path using the script did not show anything #!/bin/sh PROMT_PATH=`echo $PS1` echo $PROMPT_PATH using ...
  1. #1
    Just Joined!
    Join Date
    Mar 2009
    Posts
    3

    capture the PS1 value from a script

    I suspect it is not possible, but just not sure why..

    my PS1 is defined as my_login_name@hostname:current_path

    using the script did not show anything
    #!/bin/sh
    PROMT_PATH=`echo $PS1`
    echo $PROMPT_PATH

    using perl did not help
    #!/usr/bin/perl
    $current=$ENV{PS1}; print ("$current")

    any idea to make it work?

    thanks

  2. #2
    Linux Engineer RobinVossen's Avatar
    Join Date
    Aug 2007
    Location
    The Netherlands
    Posts
    1,422
    Code:
    #!/usr/bin/perl
    print $ENV{'PS1'};
    Should work, in perl. ( Ill try this for you in my Break).
    But, run this with perl -w and tell me the output already.

    Cheers,
    Robin
    New Users, please read this..
    Google first, then ask..

  3. #3
    Just Joined!
    Join Date
    Mar 2009
    Posts
    6
    PS1 environment variable is defined in /etc/profile, which is for login shell. When you put it into your script file and execute it, it's in non-login shell.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...