LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   exporting a command (https://www.linuxquestions.org/questions/linux-newbie-8/exporting-a-command-4175577683/)

arun natarajan 04-17-2016 08:15 PM

exporting a command
 
1 Attachment(s)
hi,

i am trying to export a cmd from .bash_profile file. Am getting the output as expected , but the content format is changing from original. Don't know why ??

PFA for my work around.

Expected output like ..

[root@server ~]# echo $a
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin

mralk3 04-17-2016 08:19 PM

Say a variable "CAT" exists in your bash profile file. It has the value of "cat".
Code:

[~]$ source .bashrc
facerip@mothership[~]$ echo $CAT
cat
[~]$

I forgot to mention that in your sourced file you need to export the variable.

Code:

export CAT=cat

arun natarajan 04-17-2016 08:46 PM

hi mralk3,

did as suggested, still getting same output.

mralk3 04-17-2016 08:50 PM

Quote:

i am trying to export a cmd from .bash_profile file. Am getting the output as expected , but the content format is changing from original.
What command are you trying to export? Please share or it is useless to help.
My apologies, I need to read in full.

Quote:

Originally Posted by arun natarajan (Post 5532663)
hi mralk3,

did as suggested, still getting same output.

You could probably use 'sed' or 'cut' to format it with new lines.

mralk3 04-17-2016 09:00 PM

This should work. There really is no reason to make a exported variable with this.

Code:

cat /etc/passwd | while read line ; do echo $line ; done

rknichols 04-17-2016 09:04 PM

Variable a is set correctly. You just need to quote it in the echo command to preserve that formatting:
Code:

echo "$a"

rknichols 04-17-2016 09:14 PM

BTW, you are not "exporting a command." When you run
Code:

a=`cat /etc/passwd`
variable a is set to the result of running that command. Subsequent changes in the content of /etc/passwd will not be reflected in the value of variable a. It's not clear what you intended.


All times are GMT -5. The time now is 09:19 AM.