![]() |
|
Programming C, bash, Python, Perl, PHP, Java, you name it. |
![]() |
|
Thread Tools | Display Modes |
|
|||
![]()
Challenge: Write a shell script to accept multiple lines of copied text and store these text lines in a shell variable.
Example text to be copied and pasted: Code:
Europe ======= Amsterdam Brussels Copenhagen Africa ====== Tunis Cairo I wrote a script myself, but wonder how somebody else would do it. After at least one person submitted a script, I will share mine here too.
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump |
|
|||
![]()
No I did not use cat. Your use of cat is very clever, but I just did not think of it because I was refining my script that used read.
I am writing a little script to automate entries for the forum News section. I use the shell read to prompt for the title, url and quote. I did not immediately realize that some news quotes were multiple lines. so I replaced the single read with a shell function that uses multiple reads. In other words I stayed within the limits of my self-imposed programming paradigm ![]() Code:
#!/bin/sh pastetext() { echo Paste text. To end paste, just type a '!' as only text at begin of line ..... while read LINE ; do if [ "x$LINE" = "x!" ] ; then break ; fi if [ "x$TEXT" = "x" ]; then TEXT="$LINE" else TEXT="$TEXT\n$LINE" fi done } cat <<END Make News for daemonforums.org ------------------------------------------------------------------------ END printf "\nURL of article/source : " read URL printf "\nTitle : " read TITLE printf "\nQuotation or description : " pastetext echo ================= TEXT to paste ============= echo $TITLE printf "From [url]$URL[/url]:[quote]$TEXT[/quote]\n" echo ================= END OF TEXT =============== # end of script
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump |
![]() |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
ask for a shell script | Simon | Programming | 5 | 27th April 2010 01:07 AM |
incrementing within a shell script? | spiderpig | Programming | 5 | 29th September 2008 08:12 PM |
Shell Script. | bsdnewbie999 | Programming | 21 | 15th July 2008 07:54 AM |
shell script with input | c0mrade | Programming | 5 | 13th July 2008 04:33 AM |
Adding multiple lines into file | c0mrade | Programming | 4 | 7th June 2008 11:03 PM |