Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Mon 22 Sep 2014, 02:34
All times are UTC - 4
 Forum index » House Training » HOWTO ( Solutions )
Howto Quickly Write A Note Without A Text Editor
Moderators: Flash, Ian, JohnMurga
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
Page 1 of 1 Posts_count  
Author Message
Dougal


Joined: 19 Oct 2005
Posts: 2505
Location: Hell more grotesque than any medieval woodcut

PostPosted: Sat 20 Aug 2011, 15:34    Post_subject:  Howto Quickly Write A Note Without A Text Editor
Sub_title: Stupid Shell Trick
 

If you want to quickly write a few lines to a file, without using mp or such other cli text editors... use a here document:
Just write:
Code:
cat >myfile <<_END
then write whatever you want (including hitting enter) and when you're done just type _END...

For example:
Code:
# cat >myfile <<_END
> bla
> meh
> _END
# cat myfile
bla
meh
#

_________________
What's the ugliest part of your body?
Some say your nose
Some say your toes
But I think it's your mind
Back to top
View user's profile Send_private_message 
rcrsn51


Joined: 05 Sep 2006
Posts: 9124
Location: Stratford, Ontario

PostPosted: Sat 20 Aug 2011, 15:52    Post_subject:  

Or just
Code:
cat > myfile

and press CTRL/D when done.
Back to top
View user's profile Send_private_message 
Laie

Joined: 20 Jan 2008
Posts: 290
Location: Germany

PostPosted: Sat 27 Aug 2011, 14:43    Post_subject:  

COOL
Back to top
View user's profile Send_private_message 
laika


Joined: 15 Jan 2007
Posts: 115

PostPosted: Mon 29 Aug 2011, 19:56    Post_subject:  

rcrsn51 wrote:
Or just...


But then no orderly > at the beginning of each line Smile Seriously, though, here files have some specific application, don't they?
Back to top
View user's profile Send_private_message 
Dougal


Joined: 19 Oct 2005
Posts: 2505
Location: Hell more grotesque than any medieval woodcut

PostPosted: Wed 31 Aug 2011, 08:39    Post_subject:  

laika wrote:
here files have some specific application, don't they?

They're a tool... you can do what you want with them.
One good usage is if you write a script and want to give a usage/help option, then rather than using echo and having to play with quoting (if your text includes quotes you'll need to escape them etc.), just write the text you want to output and enclose it in a here document.
Another place where they're is where you have a loop that reads from the output of a subshell:
If you pipe the subshell into the loop,
Code:
grep 'bla' file | while read Line ; do
  #do something
done
then the loop is part of the subshell and any variables you set in it will not be remembered.
If the loop reads from a here document
Code:
while read Line ; do
  #do something
done<<_END
$(grep 'bla' filename)
_END
then you're ok...
_________________
What's the ugliest part of your body?
Some say your nose
Some say your toes
But I think it's your mind
Back to top
View user's profile Send_private_message 
Display_posts:   Sort by:   
Page 1 of 1 Posts_count  
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » House Training » HOWTO ( Solutions )
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0534s ][ Queries: 11 (0.0081s) ][ GZIP on ]