LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-17-2016, 08:15 PM   #1
arun natarajan
Member
 
Registered: Jun 2014
Posts: 111

Rep: Reputation: Disabled
exporting a command


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
Attached Thumbnails
Click image for larger version

Name:	output format.jpg
Views:	16
Size:	155.3 KB
ID:	21553  
 
Old 04-17-2016, 08:19 PM   #2
mralk3
Slackware Contributor
 
Registered: May 2015
Distribution: Slackware
Posts: 1,900

Rep: Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050
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

Last edited by mralk3; 04-17-2016 at 08:20 PM.
 
Old 04-17-2016, 08:46 PM   #3
arun natarajan
Member
 
Registered: Jun 2014
Posts: 111

Original Poster
Rep: Reputation: Disabled
hi mralk3,

did as suggested, still getting same output.
 
Old 04-17-2016, 08:50 PM   #4
mralk3
Slackware Contributor
 
Registered: May 2015
Distribution: Slackware
Posts: 1,900

Rep: Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050
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 View Post
hi mralk3,

did as suggested, still getting same output.
You could probably use 'sed' or 'cut' to format it with new lines.

Last edited by mralk3; 04-17-2016 at 08:52 PM.
 
Old 04-17-2016, 09:00 PM   #5
mralk3
Slackware Contributor
 
Registered: May 2015
Distribution: Slackware
Posts: 1,900

Rep: Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050Reputation: 1050
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
 
Old 04-17-2016, 09:04 PM   #6
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,770

Rep: Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210
Variable a is set correctly. You just need to quote it in the echo command to preserve that formatting:
Code:
echo "$a"
 
1 members found this post helpful.
Old 04-17-2016, 09:14 PM   #7
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,770

Rep: Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210
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.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
exporting structures krisonearth Programming 1 09-13-2009 03:45 PM
Exporting a filesystem sidra Linux - Networking 2 10-17-2006 08:49 PM
exporting PATH for a command arunsri Slackware 4 03-20-2005 05:47 PM
exporting one NFS folder to another NFS and exporting it.... stellarmarine1 Linux - Networking 3 09-20-2004 06:54 AM
exporting graphics muneebs123 Linux - Newbie 1 09-07-2003 04:17 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration