LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 05-21-2010, 12:56 PM   #1
dmafcoi
LQ Newbie
 
Registered: May 2010
Posts: 22

Rep: Reputation: 0
$@ >> file with special characters


Simple logging script that allows user to enter quick notes and questions, but I can not get it to pass punctuation '?. no matter what I type after 'n' i need that to be inserted at the end of the working project note file.

Any help and working examples would be appreciated, but please also direct me to the proper reading material so I can learn something - not looking for someone to just do it for me.

usage:

Code:
bob@smith:~/notes$ n bob's script sucks?
>
script:

Code:
#!/bin/bash
# n
NF=$(cat ~/notes/wpf) # contains updated path/to/file info
TIMEN=$(date +"%m%d%g:%R")
[ -e $NF ] && echo "$TIMEN - $@ " >> $NF && exit || no_wpf
I've tried every combination (except the right one, of course) of `"', etc. and the more I read about them, the more confused I get.

The above example works fine if I

Code:
bob@smith:~/notes$ n "Bob's script sucks?"
bob@smith:~/notes$
but I don't want to have to worry about using quotes

Thanks in advance
 
Old 05-21-2010, 02:39 PM   #2
fruttenboel
Member
 
Registered: Jul 2008
Location: Tilburg NL
Distribution: Slackware 14.2 ciurrent, kernel 3.18.11
Posts: 270

Rep: Reputation: 48
Quote:
Originally Posted by dmafcoi View Post
but I don't want to have to worry about using quotes

Thanks in advance
Well, in that case you might be better off to stay in The Other System.

The single quote is part of the bash language. It's so deep inside bash that you will not be able to go around it.

This might work:
Code:
n Bob\'s work is good enough
but you would have to have the discipline to prefix every single quote with a backslash.

Quotes are part of Linux. You better learn to live with that... Or make your own version that does not act on quotes.
 
Old 05-21-2010, 03:07 PM   #3
dmafcoi
LQ Newbie
 
Registered: May 2010
Posts: 22

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by fruttenboel View Post

Well, in that case you might be better off to stay in The Other System.
...It's so deep inside bash that you will not be able to go around it.
...You better learn to live with that... Or make your own version...
Hi fruttenboel:

I appreciate you stopping by to chime in. I'm sure, because it is Linux, that it is possible and, with even more certainty, that someone is competent and helpful enough to contribute to solving it.

For other readers: The idea is to log notes quickly, without leaving the shell and not worrying so much about syntax. This is for a very fast-paced project where text is streaming and comments need to <be> made quickly, ten to twenty times per minute, then that info is appended to a text file that is accessed by another user where further comments are added to it, etc. So worrying about putting a quote or backslash in a comment is not an option, any more than using "'s while typing them

Thanks for any and all helpful posts - LQ rules - I'm learning a lot and thankful for the site.

Last edited by dmafcoi; 05-21-2010 at 03:10 PM.
 
Old 05-21-2010, 03:59 PM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,592

Rep: Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880
bash has many special characters i.e * is used file name expansion. There are several ways to use these characters literally. You can use quotes for an entire string or \ with a single character. I am not aware of any option to turn off this feature.
Is the terminal window you are using to write comments used for streaming text too?

http://tldp.org/LDP/abs/html/special-chars.html
http://linux.die.net/man/1/bash
 
Old 05-21-2010, 04:16 PM   #5
dmafcoi
LQ Newbie
 
Registered: May 2010
Posts: 22

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by michaelk View Post
...Is the terminal window you are using to write comments used for streaming text too?
Hi Michael: The streaming text comes from several source (e.g. web, remote shell,etc.) but never the same screen. We review snippets of info from a database using another unrelated script 'q refno 1527' as an example would pull up just the note fields for that record and insert just that field into the log file, then we comment on the data presented and that comment is >> to the text log file

The apostrophe is the main concern, would be nice to make quick notes without needing to relearning how to type and without needing to remember to use quotations, trying to make it as quick and natural as possible... maybe I could replace the ' when it is typed with another character using sed or something... it's a challenge to figure it out, but not critical.

Meanwhile I'm reviewing the links you provided, thank you.

-Bob
 
Old 05-21-2010, 04:33 PM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,592

Rep: Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880
Then it should be possible to run a script with a loop that asks for comments and appends to the log file.
 
1 members found this post helpful.
Old 05-21-2010, 04:56 PM   #7
dmafcoi
LQ Newbie
 
Registered: May 2010
Posts: 22

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by michaelk View Post
Then it should be possible to run a script with a loop that asks for comments and appends to the log file.
read works fine I can do all the little queries and notes from one script, hopefully, but things are looking up! It should be just as quick and easy.

Odd how when something is new, I get fixated on one little thing and can't seem to look at the big picture... forest for the trees, etc.

Thanks for the suggestion - I'm sure that'll work fine. Will post a followup.
 
Old 05-21-2010, 05:53 PM   #8
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Quote:
maybe I could replace the ' when it is typed with another character using sed or something
an alias would be better suited than sed/awk/... for this,
but the suggestion from michaelk (a script looping over lines read in) is probably better & safer
 
1 members found this post helpful.
Old 05-21-2010, 06:45 PM   #9
dmafcoi
LQ Newbie
 
Registered: May 2010
Posts: 22

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by timmeke View Post
an alias would be better suited than sed/awk/... for this,
but the suggestion from michaelk (a script looping over lines read in) is probably better & safer
hi timmeke: I'm running with using read and learning lots. From what I'm reading, I should be able to come up with a functional solution, or at least have fun trying. thanks
 
Old 05-21-2010, 10:09 PM   #10
okos
Member
 
Registered: May 2007
Location: California
Distribution: Slackware/Ubuntu
Posts: 609

Rep: Reputation: 38
Is this a class assignment?
 
Old 05-22-2010, 12:31 PM   #11
dmafcoi
LQ Newbie
 
Registered: May 2010
Posts: 22

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by okos View Post
Is this a class assignment?
no.
 
Old 05-22-2010, 02:34 PM   #12
dmafcoi
LQ Newbie
 
Registered: May 2010
Posts: 22

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by dmafcoi View Post
read works fine ... Will post a followup.
MIchael: thanks again for steering me in the right direction and encouraging me to read more. As a newbie, I don't always know the correct terms to put in the search box, and you helped me figure it out, then BOOM, I had hours of reading to do, because I knew what to look for.

Read has tons of options and I'm having lots of fun learning. This is the promised follow-up - is this something like you had in mind? At any rate, it's working just fine and does exactly what I need it to do - quick and easy entry of notes without worrying so much about quotes and formatting.

thanks [all]

Code:
#!/bin/bash
# I left out all the sub scripts
mymenu () {
        echo "e) Export Project"
        echo "b) Book Entry"
        echo "n) Notes"
	echo "q) Query to Log"
	echo "d) Exit"
}
 
while [ 1 ]
do
        mymenu
        read -s -n1 PRESSED
        case "$PRESSED" in
                "e")
                        echo "do export stuff"
                        ;;
                "b")
                        echo "do book stuff"
                        ;;
                "n")
			echo "do note stuff"
			;;
		"q")
			echo "do query stuff"
			;;
		"d")	
			exit
                        ;;
        esac
done

Last edited by dmafcoi; 05-22-2010 at 02:36 PM. Reason: typo
 
Old 05-22-2010, 04:22 PM   #13
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,592

Rep: Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880
Yes, its what I had in mind and looks like you got it.
 
Old 05-27-2010, 01:06 PM   #14
dmafcoi
LQ Newbie
 
Registered: May 2010
Posts: 22

Original Poster
Rep: Reputation: 0
nested case - if $var = 'item on this list'

What is the way to check if $var = one of the items on this list? Is a nested case the right/best way?

Also, how do I prevent the mymenu () from adding to the screen if I press a wrong key?

Code:
#!/bin/bash

mymenu () {
	echo "abc"
}

while [ 1 ]
do
	mymenu
	read -sn1 PRESSED
	case $PRESSED in
		a | b | c)
			case $PRESSED in
				a) echo "you typed a";;
				b) echo "you typed b";;
				c) echo "you typed c";;
			esac
		;;
	esac
done

Last edited by dmafcoi; 05-27-2010 at 01:09 PM. Reason: typo
 
Old 05-27-2010, 01:52 PM   #15
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,592

Rep: Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880Reputation: 5880
What was wrong with the code from post #12?
Typical response from a menu is when you press a wrong key an error message and the same menu items would be displayed again. You might want to use * case option if a b or c was not pressed.
 
  


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
removing file with special characters rsashok Linux - General 4 02-09-2010 04:08 PM
Special characters in file names Jinouchi Linux - Newbie 7 07-25-2009 11:48 AM
How to remove file with name containing only special characters abhisheknayak Linux - Newbie 5 07-04-2008 10:53 AM
Use of special characters in .netrc file jlarsen Linux - General 3 08-01-2007 10:12 AM
File Copy Issue-Special Characters fortezza Linux - Software 1 11-14-2005 07:16 AM

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

All times are GMT -5. The time now is 06:34 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