ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Some shells allow process substitution where the result of a command is substituted for a file:
Code:
#!/usr/bin/env bash
# @(#) s1 Demonstrate process substitution.
# Uncomment to run script as external user.
# export PATH="/usr/local/bin:/usr/bin:/bin"
# Infrastructure details, environment, commands for forum posts.
set +o nounset
pe() { for i;do printf "%s" "$i";done; printf "\n"; }
pl() { pe;pe "-----" ;pe "$*"; }
LC_ALL=C ; LANG=C ; export LC_ALL LANG
pe ; pe "Environment: LC_ALL = $LC_ALL, LANG = $LANG"
pe "(Versions displayed with local utility \"version\")"
c=$( ps | grep $$ | awk '{print $NF}' )
version >/dev/null 2>&1 && s=$(_eat $0 $1) || s=""
[ "$c" = "$s" ] && p="$s" || p="$c"
version >/dev/null 2>&1 && version "=o" $p diff
set -o nounset
# Define content of 2 arrays.
a=( now is the time )
b=( this is not then )
j=2
pl " Content of array element $j:"
pe ${a[$j]}
pe ${b[$j]}
pl " Results:"
diff <( echo ${a[$j]} ) <( echo ${b[$j]} )
exit 0
producing:
Code:
% ./s1
Environment: LC_ALL = C, LANG = C
(Versions displayed with local utility "version")
OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
Distribution : Debian GNU/Linux 5.0
GNU bash 3.2.39
diff (GNU diffutils) 2.8.1
-----
Content of array element 2:
the
not
-----
Results:
1c1
< the
---
> not
This is a property of the shell, not diff ... cheers, makyo
Last edited by makyo; 06-20-2010 at 07:54 PM.
Reason: ( Edit 1: minor typo )
My knowledge is too limited to understand everything that is going on here, but I've got the 'bit I wanted' to work on my script. I'll read this again at some stage, once i've a deeper understanding of things.
How do I get the piped output to read as an argument for the basename command? I know I can do it with xargs but i'm wanting to avoid this command as it throws a fit when fed punctuation.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339
Rep:
Quote:
Originally Posted by NirvanaII
Thanks makyo!
My knowledge is too limited to understand everything that is going on here, but I've got the 'bit I wanted' to work on my script. I'll read this again at some stage, once i've a deeper understanding of things.
How do I get the piped output to read as an argument for the basename command? I know I can do it with xargs but i'm wanting to avoid this command as it throws a fit when fed punctuation.
Maybe you would supply a before and after picture so we can help?
ie. are the names of mp3 files the only thing in Musiclist.txt or is there a path as well?
i also presume the after is just the name of the song without extension?
In the above example we are looking at the seventh field, of the absolute path entry for track one:
Code:
stuart@stuart:~/music transfer$ cat Musiclist.txt
/mnt/sda1/Music/Neil Young/Live/Neil Young - Don't Let it Bring You Down.mp3
/mnt/sda1/Music/Neil Young/Live/Neil Young - A Day i'n the Life (live@Gla.mp3
/mnt/sda1/Music/Neil Young/Live/Neil Young - A Day in the Life (live@Gla.mp3
/mnt/sda1/Music/Neil Young/Live/Neil Young - Out On The Weekend.mp3
/mnt/sda1/Music/Neil Young/Live/Neil Young OLD MAN.mp3
/mnt/sda1/Music/Neil Young/Live/Neil Young - Needle and the Damage Done.mp3
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.