Find the answer to your Linux question:
Results 1 to 7 of 7
How can i execute export PS1="\[[3[01;32m\]\u@\h\[3[01;34m\] \W]\]#" from a .sh script or .c file and make it work? Thanks...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Mar 2008
    Posts
    7

    How can i execute export


    How can i execute export PS1="\[[\033[01;32m\]\u@\h\[\033[01;34m\] \W]\]#" from a .sh script or .c file and make it work?


    Thanks

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,577
    Environment variables are context sensitive. Ie, they only work in the current environment, and for application started from the current environment. If you set an environment variable in a shell script, it will not be visible to the system after the script terminates. To get around, you can "source" the script with either the "source" or "." command. IE:
    Code:
    source script.sh
    
    or
    
    . script.sh
    BTW, you cannot do this with a compiled program. Once the program terminates, the variable is lost, or reverts to its previous setting.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Mar 2008
    Posts
    7

    Thumbs up

    Thanks very much..

  4. #4
    Just Joined!
    Join Date
    Mar 2008
    Posts
    7
    Another question please, is there any way to do like printf("\r\r \033[22;32m*** You are now logged in. ***\n");
    source("/root/.,a"); in a .c file

    /dev/shm/my/session.c:1467: undefined reference to `source'
    collect2: ld returned 1 exit status
    make: *** [linux] Error 1


    Thanks again and again.

  5. #5
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,577
    Some actions, such as setting the prompt in a terminal, can be set from a C program. The proper escape sequences need to be sent to the tty directly. I'm not sure that just printing them to stdout will work. You might have to open /dev/ttyx or /dev/pts/N where N is the controlling tty of the session. I haven't done this in many years, so my memory on how to do it is sketchy at best - the last time was on a Unix system about 15 years ago...
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  6. #6
    Just Joined!
    Join Date
    Mar 2008
    Posts
    7

    Unhappy

    i want to execute a .sh file from a .c file this is the problem huh ..

  7. #7
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,577
    Quote Originally Posted by blackps View Post
    i want to execute a .sh file from a .c file this is the problem huh ..
    You can, but once the shell script terminates, the environment changes are lost, and any environment changes made within your C program are likewise lost when the program terminates. There are "hacky" ways to get around this, but nothing nice and simple or reliable.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

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