LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-07-2021, 08:06 AM   #1
flyxtop
LQ Newbie
 
Registered: Apr 2013
Posts: 17

Rep: Reputation: Disabled
what does "cat > /sbin/reboot <<EOF" do in init script?


this is the init script from a ramdisk image.
After kernel finishes booting, it executes this init script.
--------------------------
/bin/busybox --install -s

rm /sbin/reboot
cat > /sbin/reboot <<EOF
#/bin/sh

exec /bin/busybox reboot -f
EOF
-------------------

I think when this script is run, the initrd has been already mounted. What does "cat > /sbin/reboot <<EOF" do?
 
Old 01-07-2021, 08:15 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447
Hi

It writes the content until the next EOF to the /sbin/reboot file - first it removes the file, then replaces it with this:
Code:
#/bin/sh

exec /bin/busybox reboot -f
 
2 members found this post helpful.
Old 01-07-2021, 08:25 AM   #3
flyxtop
LQ Newbie
 
Registered: Apr 2013
Posts: 17

Original Poster
Rep: Reputation: Disabled
Thumbs up that clearly explained it to me.

Quote:
Originally Posted by Guttorm View Post
Hi

It writes the content until the next EOF to the /sbin/reboot file - first it removes the file, then replaces it with this:
Code:
#/bin/sh

exec /bin/busybox reboot -f
Ah, that was so. Thank you! (BTW, I didn't know LQ requires Title for a reply)
 
Old 01-07-2021, 09:30 AM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,309
Blog Entries: 3

Rep: Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721Reputation: 3721
The name for that method of creating output is called a here document.

The name for the method of getting the here document, or other output, into a file is called redirection.

It can either overwrite or append.
 
  


Reply

Tags
busybox, initrd, kernel



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Shell script, what does this line do: "cat -- << EOF >${CreateScript_DeployDirs}" nkamp Linux - Newbie 4 09-03-2020 02:19 AM
initramfs - why do we need "init" in root instead of /sbin/init? ranshalit Linux From Scratch 2 01-02-2019 06:00 PM
[SOLVED] cat > filename << "EOF" syntax explanation bucovaina78 Linux - General 4 12-21-2011 03:50 PM
Chkroot scan - /sbin/init & /sbin/ifconfig INFECTED bicoba Linux - Security 4 06-07-2006 09:16 AM
bash redirection "$ cat << EOF > file" (how does this work) ninmonkeys Linux - General 1 11-09-2004 03:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:50 PM.

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