LinuxQuestions.org
Review your favorite Linux distribution.
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 10-03-2010, 12:56 AM   #1
mmhs
Member
 
Registered: Oct 2010
Posts: 99

Rep: Reputation: 1
>>> and Output redirection


hi Guys i have two questions about redirection in linux

first : what does it mean in linux >>> i know we have this type of redirection but it's undocumented .

second : i want to write a shell script cuz when a user use Output redirect if file has a Contents give an error to user an dont overwrite on this file . ( and i think we have a command in linux that do this when u use this command it's output redirect and if file has content give an error to user ) !!!!

i dont want to use appned !!

Last edited by mmhs; 10-03-2010 at 01:42 AM.
 
Old 10-03-2010, 01:16 AM   #2
malekmustaq
Senior Member
 
Registered: Dec 2008
Location: root
Distribution: Slackware & BSD
Posts: 1,613

Rep: Reputation: 433Reputation: 433Reputation: 433Reputation: 433Reputation: 433
mmhs,

Really hard to answer a hardly understandable question.

Quote:
first : what does it mean in linux >>> i know we have this type of redirection but it's undocumented .
Pipe. e.g. 'echo "The quick brown fox" >> txt.file' The sentence is written into txt.file.
 
Old 10-03-2010, 01:41 AM   #3
mmhs
Member
 
Registered: Oct 2010
Posts: 99

Original Poster
Rep: Reputation: 1
thx man but u dont understand my question >> use to append but i want to know what about this >>> in linux ( we have >>> in linux but it's undocumented (same as here document ( << ) )

and what about my second question !!
 
Old 10-03-2010, 02:12 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,251

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
I am not sure about >>>, but <<< is called a here string, see here for some detail
 
1 members found this post helpful.
Old 10-03-2010, 02:27 AM   #5
mmhs
Member
 
Registered: Oct 2010
Posts: 99

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by grail View Post
I am not sure about >>>, but <<< is called a here string, see here for some detail
thx alot man but what about my second question ??
 
Old 10-03-2010, 02:32 AM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Please give an example of >>>. It is not known by bash 3.1.7:
Code:
c@CW8:/tmp$ echo bar >>> foo
bash: syntax error near unexpected token `>'
To prevent > overwriting existing files, use set -o noclobber. Here's a terminal scrape to illustrate its usage
Code:
c@CW8:/tmp$ echo bar > foo
c@CW8:/tmp$ ls -l foo
-rw-r--r-- 1 c users 4 2010-10-03 11:54 foo
c@CW8:/tmp$ set -o noclobber
c@CW8:/tmp$ echo bar > foo
bash: foo: cannot overwrite existing file
c@CW8:/tmp$ set +o noclobber
c@CW8:/tmp$ echo barbar > foo
c@CW8:/tmp$ ls -l foo
-rw-r--r-- 1 c users 7 2010-10-03 11:54 foo
The "here document" use of << is in the bash man page and here.
 
1 members found this post helpful.
Old 10-03-2010, 02:58 AM   #7
mmhs
Member
 
Registered: Oct 2010
Posts: 99

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by catkin View Post
Please give an example of >>>. It is not known by bash 3.1.7:
Code:
c@CW8:/tmp$ echo bar >>> foo
bash: syntax error near unexpected token `>'
To prevent > overwriting existing files, use set -o noclobber. Here's a terminal scrape to illustrate its usage
Code:
c@CW8:/tmp$ echo bar > foo
c@CW8:/tmp$ ls -l foo
-rw-r--r-- 1 c users 4 2010-10-03 11:54 foo
c@CW8:/tmp$ set -o noclobber
c@CW8:/tmp$ echo bar > foo
bash: foo: cannot overwrite existing file
c@CW8:/tmp$ set +o noclobber
c@CW8:/tmp$ echo barbar > foo
c@CW8:/tmp$ ls -l foo
-rw-r--r-- 1 c users 7 2010-10-03 11:54 foo
The "here document" use of << is in the bash man page and here.
thx alot man but i have no example for >>> i hear it before an now i want to know what's this !

if i want to write a shell script to check it for dont overwrite when user use > how can i do ???

thx alot guys for help

Last edited by mmhs; 10-03-2010 at 03:00 AM.
 
Old 10-03-2010, 03:40 AM   #8
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
Quote:
Originally Posted by mmhs View Post
if i want to write a shell script to check it for dont overwrite when user use > how can i do ???

thx alot guys for help
You can use 'stat' and check the return value (the '$?' in examples below)

example for existing file
Code:
fortyfourgalena@desktop1:~$ stat version-check.sh
  File: `version-check.sh'
  Size: 1186      	Blocks: 8          IO Block: 4096   regular file
Device: 809h/2057d	Inode: 7768977     Links: 1
Access: (0755/-rwxr-xr-x)  Uid: ( 1005/fortyfourgalena)   Gid: ( 1005/fortyfourgalena)
Access: 2010-08-10 17:00:55.000000000 +0200
Modify: 2009-08-04 20:05:44.000000000 +0200
Change: 2010-07-18 20:30:09.000000000 +0200
fortyfourgalena@desktop1:~$ echo $?
0
fortyfourgalena@desktop1:~$
example for non-existing file
Code:
fortyfourgalena@desktop1:~$ stat version-chk.sh
stat: cannot stat `version-chk.sh': No such file or directory
fortyfourgalena@desktop1:~$ echo $?
1
fortyfourgalena@desktop1:~$
check the man page if necessary

Last edited by Wim Sturkenboom; 10-03-2010 at 03:42 AM.
 
1 members found this post helpful.
Old 10-03-2010, 04:22 AM   #9
mmhs
Member
 
Registered: Oct 2010
Posts: 99

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by Wim Sturkenboom View Post
You can use 'stat' and check the return value (the '$?' in examples below)

example for existing file
Code:
fortyfourgalena@desktop1:~$ stat version-check.sh
  File: `version-check.sh'
  Size: 1186      	Blocks: 8          IO Block: 4096   regular file
Device: 809h/2057d	Inode: 7768977     Links: 1
Access: (0755/-rwxr-xr-x)  Uid: ( 1005/fortyfourgalena)   Gid: ( 1005/fortyfourgalena)
Access: 2010-08-10 17:00:55.000000000 +0200
Modify: 2009-08-04 20:05:44.000000000 +0200
Change: 2010-07-18 20:30:09.000000000 +0200
fortyfourgalena@desktop1:~$ echo $?
0
fortyfourgalena@desktop1:~$
example for non-existing file
Code:
fortyfourgalena@desktop1:~$ stat version-chk.sh
stat: cannot stat `version-chk.sh': No such file or directory
fortyfourgalena@desktop1:~$ echo $?
1
fortyfourgalena@desktop1:~$
check the man page if necessary
thx man but i want check if file exists and has content give user and error and protect file from overwrite
 
Old 10-03-2010, 05:30 AM   #10
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by mmhs View Post
thx alot man but i have no example for >>> i hear it before an now i want to know what's this !
Your informant may have been mistaken. You could ask them to show you an example.

Quote:
Originally Posted by mmhs View Post
thx man but i want check if file exists and has content give user and error and protect file from overwrite
What's wrong with set -o noclobber? If I understand what you are asking for then it does exactly what you want.
 
1 members found this post helpful.
Old 10-03-2010, 05:35 AM   #11
mmhs
Member
 
Registered: Oct 2010
Posts: 99

Original Poster
Rep: Reputation: 1
it's work fine man but i want to write a shell script work same as set -o noclobber !!!
 
Old 10-03-2010, 05:43 AM   #12
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Quote:
Originally Posted by mmhs View Post
it's work fine man but i want to write a shell script work same as set -o noclobber !!!
Which you can do by using set -o noclobber in your shell script before using any >.

EDIT: like this
Code:
#!/bin/bash

set -o noclobber
echo foo > /tmp/myfile
[[ $? -ne 0 ]] && exit 1
exit 0
If /tmp/myfile does not exist, the script writes foo to it and exits normally with an exitcode of 0 (which you can show by running echo $? after running the script).

If /tmp/myfile does exist, the script generates a error message and exits with an exitcode of 1 (which you can show by running echo $? after running the script).

Last edited by catkin; 10-03-2010 at 05:50 AM.
 
  


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] Help.. on output redirection ge_shekhar Linux - Newbie 7 09-06-2010 06:52 AM
[SOLVED] Redirection output kma07 Linux - Newbie 3 05-12-2010 11:13 PM
Output / Redirection VauxhallVXR Programming 2 06-06-2009 06:10 PM
Output Redirection - Trying to output to screen and file? helptonewbie Linux - Newbie 7 03-19-2009 08:05 AM
what is output redirection? LinuxPadawan General 5 05-18-2005 01:53 PM


All times are GMT -5. The time now is 11:07 AM.

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