LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   I am trying to create 3 files... (https://www.linuxquestions.org/questions/linux-newbie-8/i-am-trying-to-create-3-files-876578/)

BMan8577 04-22-2011 04:39 PM

I am trying to create 3 files...
 
I am trying to create 3 files. A. untitled B. **'s and ||'s C. >> README!! << so what would be the best solution to use? Would using the cat command with the (>) work in this situation?

jschiwal 04-22-2011 05:03 PM

Please try to reword your question. I have no idea what the 3 files you want to create are.

BMan8577 04-22-2011 05:20 PM

They are random files that are to be created in my home directory with those file names in which they are supposed to be irrelevant. I have used the touch command to create the files. A. touch untitled file B. touch **'s and ||'s C. touch >> README!! <<. The touch command works on files A and B. The third file gives me the error: touch >> READMEls <<
-bash: syntax error near unexpected token `newline'

jschiwal 04-22-2011 05:30 PM

You probably are using characters that have special meanings to the bash shell.

For example a * is a wild card that bash will expand before the touch command sees it's own arguments.
The > and < characters are used for redirection.

You need to escape these characters, or include them in quotes. Single quotes are better because some characters like `$' still have a special meaning inside double quotes. If a filename starts with a dash, the shell will think that the filename is an argument. You need to use -- between your command options and the filename argument.

Better yet, don't create files with spaces or special characters in them. It makes handling them in the terminal difficult.

I would suggest downloading the Advanced Bash Scripting guide from the www.tldp.org website. The first chapter covers the usage of each special character.

Hevithan 04-22-2011 05:37 PM

Does your README file include the >> <<? if you type that into the terminal by itself, it says '-bash: syntax error near unexpected token `newline', Whereas letters that aren't linked just says 'no command found'. I'm not that great with this stuff, but I think the terminal recognizes symbols(-,/,#,etc.) as command to seperate or re-direct and stuff like that, Try just calling the file READMES.

If I'm wrong please let me know, This is just a guess and I would like to know how it goes ... a little knowledge goes a long way. Best of luck.



jschiwal, guess we we're typing same time lol. So my assumption of symbols being command related was right? sweeeeeeeeeet I love learning!

jschiwal 04-22-2011 05:44 PM

Hevithan: I've had some commands fail that worked on a large number of file arguments, or in a loop. I quoted the variable filename argument, but the problem turns out to be either a filename starting with a dash, or a filename containing `!'. The latter is especially nasty and hard to escape. The ! is used for bash history in an interactive bash session, but not when running scripts.

spankbot 04-22-2011 06:01 PM

Linux file names should only contain letters, numbers, the period (.), as well as - and _

You can technically use other special characters, but it's considered bad practice unless you *really* know what you're doing. Whats more, many special characters have special meaning to the shell.

Hevithan 04-22-2011 06:32 PM

Quote:

Originally Posted by spankbot (Post 4333062)
Linux file names should only contain letters, numbers, the period (.), as well as - and _

You can technically use other special characters, but it's considered bad practice unless you *really* know what you're doing. Whats more, many special characters have special meaning to the shell.

But wouldn't - and _ confuse it? I mean I use '-' alot, For help and to run things usally for stuff like $ dpkg -i, -h, -f, or -dir

Hevithan 04-22-2011 06:34 PM

well, unless it is in the filename IE Google-chromeinstall.deb ... My bad misread it :P

What you're saying is the filename can have '-' and '_' but for use as a separator, not at the front of the name, where it can be confused for a command, right?

T3RM1NVT0R 04-22-2011 07:11 PM

@ Reply
 
Try this

A. touch untitled
B. touch '**s'
C. touch '>>README<<'

Use the single quotes as I did here and I hope that will get the work done.

If you want to create them in one shot then do this: touch untitled && touch '**s' && touch '>>README<<'

jschiwal 04-22-2011 07:25 PM

A dash only causes a problem if it is the first character. An underscore as the first character usually doesn't cause a problem but looks strange. Local functions sometimes use an underscore to prevent name collision with global functions or commands. For example, you may source a script with a _ls() function.

Imagine a file named "-picture.jpg". showfoto -picture.jpg will be interpreted as "showfoto -p -i -c -t -u -r -e .jpg"

The filename might be in a variable, so "showfoto $pic" would fail if $pic is `-picture'. Your script might work for a long time, then fail because of the filename. So you need to use "showfoto -- $pic" instead to prevent this from happening if possible.

When working interactively, one method of handling strange file names is to use auto completion. Type the first few letters and hit the TAB key. The shell will complete the word, escaping characters as needed. This can be useful for handling a file that has a different encoding or foreign characters you can't type.

MTK358 04-23-2011 03:18 PM

Many programs interpret "--" as the end of the options, and any argument beginning with "-" after it will not be treated as an option.

MTK358 04-23-2011 03:19 PM

Quote:

Originally Posted by Hevithan (Post 4333093)
But wouldn't - and _ confuse it? I mean I use '-' alot, For help and to run things usally for stuff like $ dpkg -i, -h, -f, or -dir

"-" will only confuse it if it's the first character.

"_" will not confuse it. It's not a bash special character, nor do most programs interpret it specially. Where did you get the idea that "_" is special?


All times are GMT -5. The time now is 01:33 AM.