LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   create file with touch and echo output to that file (https://www.linuxquestions.org/questions/linux-newbie-8/create-file-with-touch-and-echo-output-to-that-file-4175491458/)

sachin.davra 01-16-2014 02:14 AM

create file with touch and echo output to that file
 
i am writing a .repo file using echo command after creating that file with touch command. but i am not able to do what i want.
Code:

echo "[local repo]" "\n" "name=local repository for updating packages" > /etc/yum.repos.d/local.repo
above command should write in the file like
Code:

[local_mirror]
name=local repository for updating packages


how can i achieve this task?

qrange 01-16-2014 02:17 AM

check permissions, usually only root can write to /etc

sachin.davra 01-16-2014 02:18 AM

Quote:

Originally Posted by qrange (Post 5098962)
check permissions, usually only root can write to /etc

i am trying with root only but i think command is wrong. i am not sure about command.

zhjim 01-16-2014 02:19 AM

You need to enable backslash interporetaion of echo. Use the -e option.

Just so we can help you better in future it would have been great if you would have shown what you output was. Just be as verbose as possible and as quiet as feasible.

SAbhi 01-16-2014 02:20 AM

Quote:

echo "[local repo]" "\n" "name=local repository for updating packages" > /etc/yum.repos.d/local.repo
well this doesn't seems to be nice use of echo!!! please read man echo.

try this:
Code:

echo -e "[local repo]\nname=local repository for updating packages\nbaseurl=http://some/site/some/page\ngpgcheck=0" > /etc/yum.repos.d/local.repo

sachin.davra 01-16-2014 02:28 AM

Quote:

Originally Posted by SAbhi (Post 5098965)
well this doesn't seems to be nice use of echo!!! please read man echo.

try this:
Code:

echo -e "[local repo]\nname=local repository for updating packages\nbaseurl=http://some/site/some/page\ngpgcheck=0" > /etc/yum.repos.d/local.repo

Thanks for quick response. i was not aware about -e. i used it like u mentioned above and it's done. Anyway i know this is not nice use of echo but i wanna write it in %post section of kickstart file.

Thanks to everyone for their valuable time.


All times are GMT -5. The time now is 12:49 AM.