Re: [OT] bash help
On Mon, Feb 20, 2017 at 10:46:23AM +, Andy Blanchard wrote: > On 20 February 2017 at 09:18, T_POL wrote: > > > > not sure about that but I think the "cd" command executes indeed > > but it's valid only for the scripts' environment and not for the > > shell you started the script from. > > *ding* *ding* *ding* We have a winner! > > Shells execute in their own instance of bash (or whatever) - a > subshell. The way to do this is with an alias or function, depending > on your needs (aliases don't except parameters, functions do), so > here's the function for "mdcd": > > $ mdcd() { > # additional checks here, per original post > mkdir $1 > cd $1 > } > > > Alternatively, you can force a script to run in the current shell by sourcing > it > > $ . {scriptname} > > Note the "." between the prompt and script (you can also use the more > literal "source"): > > $ source {scriptname} > > Another option, just for completeness, would be to alias sourcing a > script, e.g.: > > $ alias mdcd='. {path to script}' > A caveat I think the OP already found out. Both the sourced script and the function would be running in the users interactive shell environment, it must for the cd to be effective. Thus you do not want to "exit" from either the sourced script nor from the function as that causes the interactive shell to exit. In the function you can use "return " instead of "exit ". Jon -- Jon H. LaBadie jo...@jgcomp.com ___ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-le...@lists.fedoraproject.org
Re: [OT] bash help
On 20 February 2017 at 09:18, T_POL wrote: > > not sure about that but I think the "cd" command executes indeed > but it's valid only for the scripts' environment and not for the > shell you started the script from. *ding* *ding* *ding* We have a winner! Shells execute in their own instance of bash (or whatever) - a subshell. The way to do this is with an alias or function, depending on your needs (aliases don't except parameters, functions do), so here's the function for "mdcd": $ mdcd() { # additional checks here, per original post mkdir $1 cd $1 } Alternatively, you can force a script to run in the current shell by sourcing it $ . {scriptname} Note the "." between the prompt and script (you can also use the more literal "source"): $ source {scriptname} Another option, just for completeness, would be to alias sourcing a script, e.g.: $ alias mdcd='. {path to script}' -- Andy The only person to have all his work done by Friday was Robinson Crusoe ___ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-le...@lists.fedoraproject.org
Re: [OT] bash help
On Sun, 19 Feb 2017 05:22:44 -0800 Mike Wright wrote: > Hi all, > > My brain cell ran away from home. I have an incredibly simple script > that doesn't do what I expect. I use "mkdir DIR; cd DIR" a lot so I'm > trying to put it in a script: "~/bin/mdcd". > > After checking that $1 exists: > > dir="$1" > mkdir -p "$dir" > cd "$dir" <-- never executes > > The directory is created so there is no error there. > > Huh? Insight anyone? > > Thanks, > Mike Wright > ___ > users mailing list -- users@lists.fedoraproject.org > To unsubscribe send an email to users-le...@lists.fedoraproject.org Hi not sure about that but I think the "cd" command executes indeed but it's valid only for the scripts' environment and not for the shell you started the script from. If it's not so, may be my brain cells are gone too. Ciao ___ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-le...@lists.fedoraproject.org
Re: [OT] bash help
On Sun, Feb 19, 2017 at 02:12:35PM -0800, Joe Zeff wrote: > On 02/19/2017 05:22 AM, Mike Wright wrote: > > dir="$1" > > mkdir -p "$dir" > > cd "$dir" <-- never executes > I'm not sure why this doesn't work but you're doing it the hard way. > > mkdir -p $1 > cd $1 > > is much simpler, and might work better. Unless $1 contains any spaces, in which case the mkdir will create two or more directories; e.g.: $ p="a b" $ mkdir $p $ ls -l total 8 drwxrwxr-x. 2 davem davem 4096 Feb 20 09:07 a drwxrwxr-x. 2 davem davem 4096 Feb 20 09:07 b $ -- "You may not work around any technical limitations in the software" -- Windows Vista license ___ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-le...@lists.fedoraproject.org
Re: [OT] bash help
On 02/19/2017 03:46 PM, Patrick O'Callaghan wrote: On Sun, 2017-02-19 at 05:22 -0800, Mike Wright wrote: Hi all, My brain cell ran away from home. I have an incredibly simple script that doesn't do what I expect. I use "mkdir DIR; cd DIR" a lot so I'm trying to put it in a script: "~/bin/mdcd". After checking that $1 exists: dir="$1" mkdir -p "$dir" cd "$dir" <-- never executes The directory is created so there is no error there. Huh? Insight anyone? If it's a Shell script then it's executing in a sub-shell, which then terminates, so the current directory of the calling Shell is unchanged. To get the effect you want either use an alias or call "eval". To both Robert Nichols & Patrick O'Callaghan, Got it - after resolving a "gotcha". I'm executing this on a machine I shelled into. But after executing the alias mkcd=". /home/mike/bin/mdcd" the path is created but I'm bounced all the back to my local machine!!! Turns out the script ended with "exit 0" which apparently is executed in the context of the calling bash and logs me out. Thanks for the help ___ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-le...@lists.fedoraproject.org
Re: [OT] bash help
On Sun, 2017-02-19 at 05:22 -0800, Mike Wright wrote: > Hi all, > > My brain cell ran away from home. I have an incredibly simple script > that doesn't do what I expect. I use "mkdir DIR; cd DIR" a lot so I'm > trying to put it in a script: "~/bin/mdcd". > > After checking that $1 exists: > > dir="$1" > mkdir -p "$dir" > cd "$dir" <-- never executes > > The directory is created so there is no error there. > > Huh? Insight anyone? If it's a Shell script then it's executing in a sub-shell, which then terminates, so the current directory of the calling Shell is unchanged. To get the effect you want either use an alias or call "eval". poc ___ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-le...@lists.fedoraproject.org
Re: [OT] bash help
On 02/19/2017 07:22 AM, Mike Wright wrote: Hi all, My brain cell ran away from home. I have an incredibly simple script that doesn't do what I expect. I use "mkdir DIR; cd DIR" a lot so I'm trying to put it in a script: "~/bin/mdcd". After checking that $1 exists: dir="$1" mkdir -p "$dir" cd "$dir" <-- never executes The script runs in a child process. It changes its _own_ working directory and then exits, leaving the parent shell exactly where it was before. Scripts like that need to be _sourced_, not simply executed. It probably makes sense to set up an alias to do that: alias mkdirp=". mkdirp.sh" Then you can type "mkdirp /wherever/whatever" and it will run ". mkdirp.sh /wherever/whatever". -- Bob Nichols "NOSPAM" is really part of my email address. Do NOT delete it. ___ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-le...@lists.fedoraproject.org
Re: [OT] bash help
On 02/19/2017 05:22 AM, Mike Wright wrote: Hi all, My brain cell ran away from home. I have an incredibly simple script that doesn't do what I expect. I use "mkdir DIR; cd DIR" a lot so I'm trying to put it in a script: "~/bin/mdcd". After checking that $1 exists: dir="$1" mkdir -p "$dir" cd "$dir" <-- never executes The directory is created so there is no error there. Huh? Insight anyone? I'm not sure why this doesn't work but you're doing it the hard way. mkdir -p $1 cd $1 is much simpler, and might work better. ___ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-le...@lists.fedoraproject.org
[OT] bash help
Hi all, My brain cell ran away from home. I have an incredibly simple script that doesn't do what I expect. I use "mkdir DIR; cd DIR" a lot so I'm trying to put it in a script: "~/bin/mdcd". After checking that $1 exists: dir="$1" mkdir -p "$dir" cd "$dir" <-- never executes The directory is created so there is no error there. Huh? Insight anyone? Thanks, Mike Wright ___ users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-le...@lists.fedoraproject.org
Re: OT: bash help
On 17 August 2014 08:36, Cameron Simpson wrote: > On 16Aug2014 14:44, Mike Wright wrote: >> >> I'm trying to write a simple script that if provided an argument, uses >> that, or if nothing is provided, uses a predefined string. > > > This is general shell stuff, not bash specific. > >> if [ -n $# ] > > > This is always true. Even "0" is a nonempty string. > > Test [ $# -gt 0 ] instead. > > Though it's a matter of preference I'd prefer [ $# = 0 ] or [ $# != 0 ] tests unless you really need one of the numeric comparisons. The reason (and it doesn't actually apply for $#, hence matter of preference) is that if you have somehow ended up with a string rather than a number (e.g. an error from wc or something) then you have to think about what your comparison is going to do for that case, whereas the =! and == comparisons will do what you expect. If you do need -gt, -lt and the rest then (except for $#) it's best to check what you've got is a number first. -- imalone http://ibmalone.blogspot.co.uk -- users mailing list users@lists.fedoraproject.org To unsubscribe or change subscription options: https://admin.fedoraproject.org/mailman/listinfo/users Fedora Code of Conduct: http://fedoraproject.org/code-of-conduct Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines Have a question? Ask away: http://ask.fedoraproject.org
Re: OT: bash help
On 16Aug2014 14:44, Mike Wright wrote: I'm trying to write a simple script that if provided an argument, uses that, or if nothing is provided, uses a predefined string. This is general shell stuff, not bash specific. if [ -n $# ] This is always true. Even "0" is a nonempty string. Test [ $# -gt 0 ] instead. WORDS=$1 else WORDS="these are some words" fi I write this stuff like this: # very near the top of the script words="these are some words" [... command line parsing...] if [ $# -gt 0 ] then words=$1 shift fi Tip: run your script with "-x": sh -x my_script It will show the actual commands executed. Finally: Never use $UPPERCASE names for variables that are local to your script. Use lower case for script-local variables. Why? - exported variables are by convention names with upper case, so using lower case makes it obvious that this variable is for your script versus general use (like $PATH) - if a variable _is_ in the exported environment, and your script uses that name, the changed value will get exported to all the commands your script runs even if you don't export it yourself: it came in from the extrernal environment and it will automatically go out with the environment given to subcommands - you can't expected (or be expected) to know every exported name that can possibly be used, nor even those commonly in use; by adopting the use of lower case names for script-local variable you entirely avoid needing omniscience about exported names. You're writing the script with $WORDS probably because there are many many example scripts like it. They've been written by people who have never thought this through. Cheers, Cameron Simpson Fatal error! Hit any user to continue... - Phillip Coles -- users mailing list users@lists.fedoraproject.org To unsubscribe or change subscription options: https://admin.fedoraproject.org/mailman/listinfo/users Fedora Code of Conduct: http://fedoraproject.org/code-of-conduct Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines Have a question? Ask away: http://ask.fedoraproject.org
Re: OT: bash help
08/16/2014 04:14 PM, Mark C. Allman wrote: On Sun, 2014-08-17 at 00:42 +0200, Suvayu Ali wrote: On Sat, Aug 16, 2014 at 02:44:14PM -0700, Mike Wright wrote: Hi all, I'm trying to write a simple script that if provided an argument, uses that, or if nothing is provided, uses a predefined string. if [ -n $# ] This will always be true. -n tests if a string is empty or not. 0 counts as non-empty. You should use one of the comparison operators. Try something like this: [ $# -gt 0 ] Hope this helps, -- Suvayu Open source is the future. It sets us free. Are you looking for behavior that the following test script demonstrates? #!/bin/bash theArg=${1:-The Default Value} echo $theArg Thanx Mark, Very elegant. I like it. I was just going through the section on "variable substitution" in "Unix in a Nutshell" and saw that. -- users mailing list users@lists.fedoraproject.org To unsubscribe or change subscription options: https://admin.fedoraproject.org/mailman/listinfo/users Fedora Code of Conduct: http://fedoraproject.org/code-of-conduct Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines Have a question? Ask away: http://ask.fedoraproject.org
Re: OT: bash help
On Sun, 2014-08-17 at 00:42 +0200, Suvayu Ali wrote: > On Sat, Aug 16, 2014 at 02:44:14PM -0700, Mike Wright wrote: > > Hi all, > > > > I'm trying to write a simple script that if provided an argument, uses that, > > or if nothing is provided, uses a predefined string. > > > > if [ -n $# ] > > This will always be true. -n tests if a string is empty or not. 0 > counts as non-empty. You should use one of the comparison operators. > Try something like this: > > [ $# -gt 0 ] > > Hope this helps, > > -- > Suvayu > > Open source is the future. It sets us free. Are you looking for behavior that the following test script demonstrates? #!/bin/bash theArg=${1:-The Default Value} echo $theArg -- Mark C. Allman, PMP, CSM Founder, See How You Ski, www.seehowyouski.com 617-947-4263, Twitter: @allmanpc -- users mailing list users@lists.fedoraproject.org To unsubscribe or change subscription options: https://admin.fedoraproject.org/mailman/listinfo/users Fedora Code of Conduct: http://fedoraproject.org/code-of-conduct Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines Have a question? Ask away: http://ask.fedoraproject.org
Re: OT: bash help
On Sat, Aug 16, 2014 at 02:44:14PM -0700, Mike Wright wrote: > Hi all, > > I'm trying to write a simple script that if provided an argument, uses that, > or if nothing is provided, uses a predefined string. > > if [ -n $# ] This will always be true. -n tests if a string is empty or not. 0 counts as non-empty. You should use one of the comparison operators. Try something like this: [ $# -gt 0 ] Hope this helps, -- Suvayu Open source is the future. It sets us free. -- users mailing list users@lists.fedoraproject.org To unsubscribe or change subscription options: https://admin.fedoraproject.org/mailman/listinfo/users Fedora Code of Conduct: http://fedoraproject.org/code-of-conduct Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines Have a question? Ask away: http://ask.fedoraproject.org
Re: OT: bash help
On 08/16/2014 02:44 PM, Mike Wright wrote: I'm trying to write a simple script that if provided an argument, uses that, or if nothing is provided, uses a predefined string. I found this example that might help: http://tldp.org/LDP/abs/html/comparison-ops.html#STRTEST -- users mailing list users@lists.fedoraproject.org To unsubscribe or change subscription options: https://admin.fedoraproject.org/mailman/listinfo/users Fedora Code of Conduct: http://fedoraproject.org/code-of-conduct Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines Have a question? Ask away: http://ask.fedoraproject.org
Re: OT: bash help
On Sat, Aug 16, 2014 at 02:44:14PM -0700, Mike Wright wrote: > Hi all, > > I'm trying to write a simple script that if provided an argument, > uses that, or if nothing is provided, uses a predefined string. > > if [ -n $# ] > then > WORDS=$1 > else > WORDS="these are some words" > fi > echo $WORDS; > > The second case is always comes back "". > > But if I write > > WORDS='these are some words' > echo $WORDS > > I get the assigned string. > > Why doesn't the assignment work when inside an if/then? How do I > make it work? What's the difference between the case where the > assignment is inside the if/then and outside the if/then? This works: #!/bin/sh if [ $# -ne 0 ] then WORDS=$1 else WORDS="these are some words" fi echo $WORDS the hashbang line should be used, but doesn't actually change the output of this script. "$#" is an integer, not a string, and that it should therefore be tested as an integer and not a string, hence the if statement being: if [ $# -ne 0 ] and you don't NEED the quotes around the literal string, though it doesn't harm to put them there, perhaps as documentation to make clear what you intention is. -- --- .Fred Smith / ( /__ ,__. __ __ / __ : / // / /__) / / /__) .+' Home: fre...@fcshome.stoneham.ma.us // (__ (___ (__(_ (___ / :__ 781-438-5471 Jude 1:24,25 - -- users mailing list users@lists.fedoraproject.org To unsubscribe or change subscription options: https://admin.fedoraproject.org/mailman/listinfo/users Fedora Code of Conduct: http://fedoraproject.org/code-of-conduct Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines Have a question? Ask away: http://ask.fedoraproject.org
Re: OT: bash help
On 08/16/2014 02:44 PM, Mike Wright wrote: if [ -n $# ] then WORDS=$1 else WORDS="these are some words" fi echo $WORDS; The second case is always comes back "". But if I write WORDS='these are some words' echo $WORDS I get the assigned string. In your first example, you use full quotes (") but in your second, you use single ('). Try using single quotes and see if it makes a difference. -- users mailing list users@lists.fedoraproject.org To unsubscribe or change subscription options: https://admin.fedoraproject.org/mailman/listinfo/users Fedora Code of Conduct: http://fedoraproject.org/code-of-conduct Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines Have a question? Ask away: http://ask.fedoraproject.org
OT: bash help
Hi all, I'm trying to write a simple script that if provided an argument, uses that, or if nothing is provided, uses a predefined string. if [ -n $# ] then WORDS=$1 else WORDS="these are some words" fi echo $WORDS; The second case is always comes back "". But if I write WORDS='these are some words' echo $WORDS I get the assigned string. Why doesn't the assignment work when inside an if/then? How do I make it work? What's the difference between the case where the assignment is inside the if/then and outside the if/then? TIA, Mike Wright -- users mailing list users@lists.fedoraproject.org To unsubscribe or change subscription options: https://admin.fedoraproject.org/mailman/listinfo/users Fedora Code of Conduct: http://fedoraproject.org/code-of-conduct Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines Have a question? Ask away: http://ask.fedoraproject.org
Re: OT: bash help
On 07Jul2013 20:38, Ian Malone wrote: | On 7 July 2013 20:18, Mike Wright wrote: | >>> I'm trying to write a bash command to transcode some videos into audios | >>> but am having trouble with filenames that contain spaces. | >>> | >>> ls *flv | >>> | >>> returns this: | >>> | >>> Jorge Drexler - Al otro Lado del Río.flv | >>> | >>> But in a bash for loop it doesn't work. | >>> | >>> for f in `ls *flv`; do echo $f; done [...] | | As you've discovered, spaces in machineable filenames aren't great. | However for this case you may want to consider: | for F in *flv ; do echo "$F" ; done | The expanded *flv items are kept as single tokens. In fact this is why | "ls *flv" works to start with, it's the shell that expands the * | matches (globbing), not the ls command. ls just gets the separate file | names as arguments. I would like to second Ian's advice here. Avoid mucking with IFS if you can possibly help it. His suggestion to just go straight for: for f in *.flv do ... work with "$f" (note the quotes) ... done is the correct one. No mucking about needed at all. IFS is a recipes for disaster. It has certain very limited uses, but is usually a code smell indicating you're doing things the wrong way. The shell is actually quite good at handling filenames, even those with spaces and other punctuation, provided you take a little care. If you are writing a script to work on these things, hacking with IFS is asking for trouble - it _may_ present apparently correct behaviour for your current set of files, but it is just moving the goalposts instead of fixing the problem. Make your script robust without IFS and it won't break on you in the future. While we're on the topic of annoying filenames, may I point you at a few small scripts I find useful for tidying up (disclaimer: yeah, I wrote them): frename https://bitbucket.org/cameron_simpson/css/src/tip/bin/frename Renames files using a perl expression. Same functionality as Larry Wall's rename script, slightly tweaked. __ https://bitbucket.org/cameron_simpson/css/src/tip/bin-cs/__ Wrapper for frename, replaces spaces with underscores in filenames. With no arguments, works on *' '*, so I usually just run the command "__". _% https://bitbucket.org/cameron_simpson/css/src/tip/bin-cs/_% Wrapper for frename, replaces %xx with its matching character and also replaces spaces with underscores in filenames. With no arguments, works on *'%'*, so I usually just run the command "_%". Very handy for URL downloads than haven't been unmunged. lc https://bitbucket.org/cameron_simpson/css/src/tip/bin-cs/lc Lowercases filesnames and also does the %xx and spaces thing and turns "&" into "+". Really rather overkill. Handy for normalising mixed-case file collections if you don't want to preserve the case. I don't use this as much as I once did. Anyway, I find __ and _% very handy sometimes. Cheers, -- Cameron Simpson Sattinger's Second Law: Even though you've plugged it in, it still won't work until you switch it on. -- users mailing list users@lists.fedoraproject.org To unsubscribe or change subscription options: https://admin.fedoraproject.org/mailman/listinfo/users Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines Have a question? Ask away: http://ask.fedoraproject.org
Re: OT: bash help
Once, long ago--actually, on Sun, Jul 07, 2013 at 02:18:16PM CDT--Mike Wright (mike.wri...@mailinator.com) said: > exactly what I needed. I'd never discovered IFS before As you've discovered, it's quite useful to manipulate IFS. Just a suggestion, however. In scripts where you modify IFS, do something like: IFSAVE=$IFS; ...do stuff... IFS=$IFSAVE Depending on what you're doing to/with IFS, it can lead to confusion with other commands if it's not as expected. Cheers, -- Dave Ihnat dih...@dminet.com -- users mailing list users@lists.fedoraproject.org To unsubscribe or change subscription options: https://admin.fedoraproject.org/mailman/listinfo/users Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines Have a question? Ask away: http://ask.fedoraproject.org
Re: OT: bash help
On 7-7-13 11:29:05 Mike Wright wrote: > I'm trying to write a bash command to transcode some videos into audios > but am having trouble with filenames that contain spaces. > > ls *flv > > returns this: > > Jorge Drexler - Al otro Lado del Río.flv > > But in a bash for loop it doesn't work. > > for f in `ls *flv`; do echo $f; done > > returns this: > > Jorge > Drexler > - > Al > otro > Lado > del > Río.flv Use another shell? zsh does this: garry@vfr$ touch foo\ bar garry@vfr$ for f in `ls foo*`;do echo $f;done foo bar garry@vfr$ In contrast, bash does: garry@vfr$ bash %n@%m$ for f in `ls foo*`;do echo $f;done foo bar %n@%m$ exit On 7-7-13 20:38:30 Ian Malone wrote: > As you've discovered, spaces in machineable filenames aren't great. > However for this case you may want to consider: > for F in *flv ; do echo "$F" ; done This is probably the best solution offered, though. -- Garry T. Williams -- users mailing list users@lists.fedoraproject.org To unsubscribe or change subscription options: https://admin.fedoraproject.org/mailman/listinfo/users Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines Have a question? Ask away: http://ask.fedoraproject.org
Re: OT: bash help
On 7 July 2013 20:18, Mike Wright wrote: > 07/07/2013 12:03 PM, Steve Searle wrote: >> >> Around 07:29pm on Sunday, July 07, 2013 (UK time), Mike Wright scrawled: >> >>> I'm trying to write a bash command to transcode some videos into audios >>> but am having trouble with filenames that contain spaces. >>> >>> ls *flv >>> >>> returns this: >>> >>> Jorge Drexler - Al otro Lado del Río.flv >>> >>> But in a bash for loop it doesn't work. >>> >>> for f in `ls *flv`; do echo $f; done >>> >>> returns this: >>> >>> Jorge >>> Drexler >>> - >>> Al >>> otro >>> Lado >>> del >>> Río.flv >>> >>> Anybody know how to keep $f intact? >> >> >> Look at the use of the IFS internal variable in bash and do something >> like: >> >> IFS=$(echo -en "\n\b"); for f in `ls *flv`; do echo $f; done >> > exactly what I needed. I'd never discovered IFS before > > all my youtube soundtracks can now move to google music! woohoo!!! > As you've discovered, spaces in machineable filenames aren't great. However for this case you may want to consider: for F in *flv ; do echo "$F" ; done The expanded *flv items are kept as single tokens. In fact this is why "ls *flv" works to start with, it's the shell that expands the * matches (globbing), not the ls command. ls just gets the separate file names as arguments. -- imalone http://ibmalone.blogspot.co.uk -- users mailing list users@lists.fedoraproject.org To unsubscribe or change subscription options: https://admin.fedoraproject.org/mailman/listinfo/users Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines Have a question? Ask away: http://ask.fedoraproject.org
Re: OT: bash help
07/07/2013 12:03 PM, Steve Searle wrote: Around 07:29pm on Sunday, July 07, 2013 (UK time), Mike Wright scrawled: I'm trying to write a bash command to transcode some videos into audios but am having trouble with filenames that contain spaces. ls *flv returns this: Jorge Drexler - Al otro Lado del Río.flv But in a bash for loop it doesn't work. for f in `ls *flv`; do echo $f; done returns this: Jorge Drexler - Al otro Lado del Río.flv Anybody know how to keep $f intact? Look at the use of the IFS internal variable in bash and do something like: IFS=$(echo -en "\n\b"); for f in `ls *flv`; do echo $f; done exactly what I needed. I'd never discovered IFS before all my youtube soundtracks can now move to google music! woohoo!!! -- users mailing list users@lists.fedoraproject.org To unsubscribe or change subscription options: https://admin.fedoraproject.org/mailman/listinfo/users Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines Have a question? Ask away: http://ask.fedoraproject.org
Re: OT: bash help
Around 07:29pm on Sunday, July 07, 2013 (UK time), Mike Wright scrawled: > I'm trying to write a bash command to transcode some videos into audios > but am having trouble with filenames that contain spaces. > > ls *flv > > returns this: > > Jorge Drexler - Al otro Lado del Río.flv > > But in a bash for loop it doesn't work. > > for f in `ls *flv`; do echo $f; done > > returns this: > > Jorge > Drexler > - > Al > otro > Lado > del > Río.flv > > Anybody know how to keep $f intact? Look at the use of the IFS internal variable in bash and do something like: IFS=$(echo -en "\n\b"); for f in `ls *flv`; do echo $f; done Steve -- Play Champions - my free football predictions game at: http://www.stevesearle.com/champs/about.html 20:00:34 up 44 days, 23:20, 1 user, load average: 0.01, 0.02, 0.00 pgpyxmuNTbXep.pgp Description: PGP signature -- users mailing list users@lists.fedoraproject.org To unsubscribe or change subscription options: https://admin.fedoraproject.org/mailman/listinfo/users Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines Have a question? Ask away: http://ask.fedoraproject.org
OT: bash help
Hi all, I'm trying to write a bash command to transcode some videos into audios but am having trouble with filenames that contain spaces. ls *flv returns this: Jorge Drexler - Al otro Lado del Río.flv But in a bash for loop it doesn't work. for f in `ls *flv`; do echo $f; done returns this: Jorge Drexler - Al otro Lado del Río.flv Anybody know how to keep $f intact? Thanks experts, Mike Wright -- users mailing list users@lists.fedoraproject.org To unsubscribe or change subscription options: https://admin.fedoraproject.org/mailman/listinfo/users Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines Have a question? Ask away: http://ask.fedoraproject.org