LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-17-2010, 02:33 AM   #1
nescalona
LQ Newbie
 
Registered: Mar 2010
Posts: 6

Rep: Reputation: 0
Understanding a line of bash


Can someone explain to me what this line means? I get the redirection part at the end, but I didn't know you could pipe to cp like that. And what is the deal with the brackets. Regex? I know what the vars 'skel' and 'home' are but i can't tell what it's doing.

Code:
yes n|cp -ai -R ${skel}/{[^.],.[^.],..?}* ${home} 2>/dev/null >/dev/null
And why would it give me:

Code:
yes: standard output: broken pipe
yes: write error
Thanks!

Last edited by nescalona; 04-17-2010 at 02:37 AM.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 04-17-2010, 03:22 AM   #2
nescalona
LQ Newbie
 
Registered: Mar 2010
Posts: 6

Original Poster
Rep: Reputation: 0
I think I sorta get it... the "n"s are piped to cp in order to skip past all conflicts that "-i" asks about. The thing between braces looks like a fancy way of copying all files that gets around bash's weird globbing of dotfiles.

But why would it fail?
 
Old 04-17-2010, 04:16 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

The part between the braces is called brace expansion (a bash feature), which can generate strings. Brace expansion is performed before any other expansions and can be nested (which is true in your example).

This: {[^.],.[^.],..?} is seen by bash as 3 "expansions" (comma separated):

[^.] -> files starting with any normal character
.[^.] -> files starting with a dot followed by any normal character
..? -> files starting with 2 dots and a single normal character

The * after the {..,..,..} command tells bash it is not limited to the first one (or two) characters mentioned the the brace expansion.

I'm not sure why the command fails with a broken pipe error, it works on my linux box. Are you trying this on a linux or an OS-X box?

BTW: The -R in the command shown isn't needed. The -a (which is short for -dpR) already takes care of it.

Hope this helps.
 
2 members found this post helpful.
Old 04-17-2010, 06:06 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
The pipe probably fails because the cp command fails. You may be able to find out more by running the cp command at the command prompt, replacing the variables with their known values. Alternatively it may help to echo ${skel}/{[^.],.[^.],..?}*, replacing $skel with the known value.
 
2 members found this post helpful.
  


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
Help understanding a bash script cylon Linux - Newbie 4 09-16-2009 10:04 AM
Problem understanding line in script snowman81 Programming 3 02-09-2008 09:58 PM
bash script, understanding variables antis Programming 5 11-15-2007 04:27 AM
iptables: not understanding a specific line. xpucto Linux - Security 5 03-21-2006 03:14 PM
burning cdrs using cdrecord (ver2.0) from the command line (understanding) hamster Linux - General 2 05-13-2003 06:38 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07: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
Open Source Consulting | Domain Registration