LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Learning Special Characters (https://www.linuxquestions.org/questions/linux-newbie-8/learning-special-characters-4175613340/)

Hcardinal 09-06-2017 09:54 AM

Learning Special Characters
 
Hey guys, I need some help figuring out how to make bash not consider these special characters.
Here's the question:

Exercise 1: Review the following file names and identify the special characters. Once you’ve identified the special characters, re-write the file name with the proper escaping of special characters.
  1. ‘A super important file.’
  2. ‘Peanut-Butter & Jelly’
  3. ‘Linux > Windows’
  4. ‘Big ole sacks of $$$’
  5. ‘\ Filename with BackSlashes \’

For some reason this is super confusing to me, thanks in advance for the help!

Sefyir 09-06-2017 10:00 AM

What is confusing?
Try breaking down your question into what specifically you are not understanding.

Escaping? special characters?

Hcardinal 09-06-2017 10:02 AM

Quote:

Originally Posted by Sefyir (Post 5756213)
What is confusing?
Try breaking down your question into what specifically you are not understanding.

Escaping? special characters?

How to make BASH not see those as special characters.
For example, the first one, would it be \A\ \super\ \important\ \file\?

I don't quite understand where the \ goes to cancel out each "Special character".

rtmistler 09-06-2017 10:14 AM

Hi Hcardinal and welcome to LQ.

Please refer to our Welcome to LQ link for information about how to ask a more effective question.

Be aware that if this is an assignment, it is not a problem posting questions about it, however assignment or not, our guidance is that you should indicate what you have personally tried, or offered more details similar to what you've done with your first follow-up. Meanwhile an LQ Rule is to not post assignments verbatim, which you appear to have done.

You seem to be reading a lesson, be that for personal learning or as part of course. My experience is that prior to an exercise such as this, whatever the reading reference is, will inform you what special characters include. Therefore you should know if capital letters are considered special versus not. A: They are not.

Since this is regular expressions and special character delimiters. A simple suggestion is to go to a Linux system, find a place which has at least one .txt file that does not have to have any of these strings and then try them out using grep:
Code:

$ grep A super important file *.txt
What happens?

It complains about "super".
It complains about "important".
It complains about "file"

It does not complain about "A"

So try:
Code:

$ grep A\ super\ important\ file *.txt
And once again, it is irrelevant that any TXT files contain that string, however what you'll find is now the shell will not complain to you about your search string, because you have delimited it. Meanwhile if you do delimit the capital A it will not complain also. This only means that it does not care if you overdo it.

ondoho 09-07-2017 01:35 PM

Quote:

Originally Posted by Hcardinal (Post 5756215)
I don't quite understand where the \ goes to cancel out each "Special character".

well then try.
do your homework yourself, don't copy it down from your neighbor.

you do have a bash shell to try things out, don't you?

JJJCR 09-07-2017 09:15 PM

Shortcuts, will take you where you want to go easily.

But understanding the basics makes a solid ground.

Try this link: https://www.shellscript.sh/escape.html

Grab Linux installed it in a Virtual environment, and do the bash yourself.

sundialsvcs 09-12-2017 11:39 AM

This is a good homework exercise, and you really do need to work through it yourself. :tisk:

These well-chosen examples are representative of things that you will encounter and that you will need to be able to do. There are no short-cuts. Don't shortchange yourself.

If you don't entirely understand the question, go to your instructor(!) for clarification. This is the only way that your instructor will become aware that there is confusion concerning the question. Don't leave him/her in the dark: classroom learning needs the very active participation of both instructor and student. (Spoken by someone who's been in the front of the room ...)


All times are GMT -5. The time now is 06:46 AM.