LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 04-22-2011, 04:39 PM   #1
BMan8577
Member
 
Registered: Apr 2011
Posts: 73

Rep: Reputation: 0
Question 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?
 
Old 04-22-2011, 05:03 PM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
Please try to reword your question. I have no idea what the 3 files you want to create are.
 
Old 04-22-2011, 05:20 PM   #3
BMan8577
Member
 
Registered: Apr 2011
Posts: 73

Original Poster
Rep: Reputation: 0
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'
 
Old 04-22-2011, 05:30 PM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
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.
 
Old 04-22-2011, 05:37 PM   #5
Hevithan
Member
 
Registered: Apr 2011
Location: Washington State
Distribution: Zorin5-(Ubuntu 11.04) // Backtrack 5-(Ubuntu 10.04) // Dreamlinux 3.5-(Debian)
Posts: 275
Blog Entries: 5

Rep: Reputation: 40
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!

Last edited by Hevithan; 04-22-2011 at 05:40 PM. Reason: to include jschiwal's post
 
Old 04-22-2011, 05:44 PM   #6
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
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.
 
Old 04-22-2011, 06:01 PM   #7
spankbot
Member
 
Registered: Aug 2007
Posts: 131

Rep: Reputation: 16
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.
 
Old 04-22-2011, 06:32 PM   #8
Hevithan
Member
 
Registered: Apr 2011
Location: Washington State
Distribution: Zorin5-(Ubuntu 11.04) // Backtrack 5-(Ubuntu 10.04) // Dreamlinux 3.5-(Debian)
Posts: 275
Blog Entries: 5

Rep: Reputation: 40
Quote:
Originally Posted by spankbot View Post
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
 
Old 04-22-2011, 06:34 PM   #9
Hevithan
Member
 
Registered: Apr 2011
Location: Washington State
Distribution: Zorin5-(Ubuntu 11.04) // Backtrack 5-(Ubuntu 10.04) // Dreamlinux 3.5-(Debian)
Posts: 275
Blog Entries: 5

Rep: Reputation: 40
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?
 
Old 04-22-2011, 07:11 PM   #10
T3RM1NVT0R
Senior Member
 
Registered: Dec 2010
Location: Internet
Distribution: Linux Mint, SLES, CentOS, Red Hat
Posts: 2,385

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
@ 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<<'

Last edited by T3RM1NVT0R; 04-22-2011 at 07:14 PM.
 
Old 04-22-2011, 07:25 PM   #11
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
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.
 
Old 04-23-2011, 03:18 PM   #12
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
Many programs interpret "--" as the end of the options, and any argument beginning with "-" after it will not be treated as an option.
 
Old 04-23-2011, 03:19 PM   #13
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721Reputation: 721
Quote:
Originally Posted by Hevithan View Post
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?
 
  


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
[SOLVED] [SAMBA] How to track windows user access , create files /modify files on linux SMB efciem Linux - Server 2 05-16-2010 08:45 AM
help create this files gsel Linux - Newbie 5 02-15-2008 01:52 PM
how to create this files gsel Programming 3 02-14-2008 08:38 AM
Samba: "homes" share, cannot create directories, can create files Herg Linux - Software 1 09-14-2006 08:48 AM
Linux, Create Dirs=no, Create files=yes. Possible? tisource Linux - General 4 01-12-2004 10:05 PM

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

All times are GMT -5. The time now is 02:56 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration