bash script: dir1,dir2,dir3 expansion not working as expected from variable, for picking a random fileTrouble using cd command with “~” or “$HOME” in bash scriptinggsettings not working from within bash functionEnvironment Variable seems to be set yet not workingHow to get BASH to use * wildcard in command?Quotation Mark-InceptionSFTP in a cron jobVariable not stored while executing bash commands via gnome-terminalMoving a bash script to /bin directoryWild card expansion that works on command line but not in a bash scriptHow to pass a regex when finding a directory path in bash?

Minimum distance between holes in inner tube

Can you find x?

What exactly is the 'online' in OLAP and OLTP?

What happens to Cessna electric flaps that are moving when power is lost?

If I wouldn't want to read the story, is writing it still a good idea?

Can there be an UN resolution to remove a country from the UNSC?

What is the origin of Scooby-Doo's name?

How is hair tissue mineral analysis performed?

Dates on degrees don’t make sense – will people care?

Can Ogre clerics use Purify Food and Drink on humanoid characters?

How does a blind passenger not die, if driver becomes unconscious

Java TreeMap.floorKey() equivalent for std::map

What is "industrial ethernet"?

What did River say when she woke from her proto-comatose state?

Trainee keeps missing deadlines for independent learning

Parameterize chained calls to a utility program in Bash

Is it damaging to turn off a small fridge for two days every week?

Why does the Saturn V have standalone inter-stage rings?

Does this Wild Magic result affect the sorcerer or just other creatures?

Suggested order for Amazon Prime Doctor Who series

Should I prioritize my 401k over my student loans?

How would modern naval warfare have to have developed differently for battleships to still be relevant in the 21st century?

Count All Possible Unique Combinations of Letters in a Word

How do I set an alias to a terminal line?



bash script: dir1,dir2,dir3 expansion not working as expected from variable, for picking a random file


Trouble using cd command with “~” or “$HOME” in bash scriptinggsettings not working from within bash functionEnvironment Variable seems to be set yet not workingHow to get BASH to use * wildcard in command?Quotation Mark-InceptionSFTP in a cron jobVariable not stored while executing bash commands via gnome-terminalMoving a bash script to /bin directoryWild card expansion that works on command line but not in a bash scriptHow to pass a regex when finding a directory path in bash?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








6















I have a problem, with this simple script (pick a random file):



#!/usr/bin/env bash
set -x
srcDir="/home/user/Desktop/wallPapers/dir1,dir2,dir3"
randomFile=$(find "$srcDir" -type f -iname "*.jpg" | shuf -n 1)
printf '[%s]n' $randomFile
set +x


The problem is that while I can type this at the command line (and works perfectly fine):



find /home/user/Desktop/wallPapers/dir1,dir2,dir3 -type f -iname "*.jpg"


Then the bash debugging set-commands (set -x and +x) tells me, that for some reason bash both encloses the directory string with single quotation marks and it also replaces the double quotation marks with single quotation marks?



./script.sh
+ srcDir='/home/user/Desktop/wallPapers/dir1,dir2,dir3'
++ find '/home/user/Desktop/wallPapers/dir1,dir2,dir3' -type f -iname '"*.jpg"'
find: ‘/home/user/Desktop/wallPapers/dir1,dir2,dir3’: No such file or directory
+ randomFile=
+ printf '[%s]n'
[]
+ set +x


I understand, this is what bash sees, when the script runs:



find '/home/user/Desktop/wallPapers/dir1,dir2,dir3' -type -iname '*.jpg'


And this causes the "No such file or directory"-message, very very annoying... I do not understand, why it inserts these single quotation marks, I want double quotation marks used instead, just like on the command line... Could anyone please explain, I would be happy for that, thanks!










share|improve this question
























  • It's not "*.jpg" that doesn't happen, it's dir1,dir2,dir3.

    – Charles Duffy
    Jun 5 at 15:47











  • Thank you very much. On second thought: Isn't it both? I also don't think '.jpg' expands correctly (if there wasn't a single quotation mark around '.jpg', which was shown from inside the "set -x" and "set +x"-section, I would agree... But I honestly also do not know why bash encloses the directory and the file inside single quotation mark...

    – Okay Dokey
    Jun 5 at 18:48











  • *.jpg, in find . -iname '*.jpg', is parsed by find, not by bash; it's expected that it not be expanded by the shell -- if it were, find would never see it. Thus, having a single layer of syntactic quotes (and no literal quotes) is entirely correct and desired in that case. ("Literal" quotes are quotes that are part of the data, and thus passed to find; "syntactic" quotes are quotes that are part of the shell syntax, and thus consumed by bash itself).

    – Charles Duffy
    Jun 5 at 20:05












  • @Charles Duffy Ok, thank you. I'm not that used to the terminology about syntactic / literal quotes. But it's very helpful of you elaborate, thank you very much (eventually I'll hopefully learn it)...

    – Okay Dokey
    Jun 6 at 15:26

















6















I have a problem, with this simple script (pick a random file):



#!/usr/bin/env bash
set -x
srcDir="/home/user/Desktop/wallPapers/dir1,dir2,dir3"
randomFile=$(find "$srcDir" -type f -iname "*.jpg" | shuf -n 1)
printf '[%s]n' $randomFile
set +x


The problem is that while I can type this at the command line (and works perfectly fine):



find /home/user/Desktop/wallPapers/dir1,dir2,dir3 -type f -iname "*.jpg"


Then the bash debugging set-commands (set -x and +x) tells me, that for some reason bash both encloses the directory string with single quotation marks and it also replaces the double quotation marks with single quotation marks?



./script.sh
+ srcDir='/home/user/Desktop/wallPapers/dir1,dir2,dir3'
++ find '/home/user/Desktop/wallPapers/dir1,dir2,dir3' -type f -iname '"*.jpg"'
find: ‘/home/user/Desktop/wallPapers/dir1,dir2,dir3’: No such file or directory
+ randomFile=
+ printf '[%s]n'
[]
+ set +x


I understand, this is what bash sees, when the script runs:



find '/home/user/Desktop/wallPapers/dir1,dir2,dir3' -type -iname '*.jpg'


And this causes the "No such file or directory"-message, very very annoying... I do not understand, why it inserts these single quotation marks, I want double quotation marks used instead, just like on the command line... Could anyone please explain, I would be happy for that, thanks!










share|improve this question
























  • It's not "*.jpg" that doesn't happen, it's dir1,dir2,dir3.

    – Charles Duffy
    Jun 5 at 15:47











  • Thank you very much. On second thought: Isn't it both? I also don't think '.jpg' expands correctly (if there wasn't a single quotation mark around '.jpg', which was shown from inside the "set -x" and "set +x"-section, I would agree... But I honestly also do not know why bash encloses the directory and the file inside single quotation mark...

    – Okay Dokey
    Jun 5 at 18:48











  • *.jpg, in find . -iname '*.jpg', is parsed by find, not by bash; it's expected that it not be expanded by the shell -- if it were, find would never see it. Thus, having a single layer of syntactic quotes (and no literal quotes) is entirely correct and desired in that case. ("Literal" quotes are quotes that are part of the data, and thus passed to find; "syntactic" quotes are quotes that are part of the shell syntax, and thus consumed by bash itself).

    – Charles Duffy
    Jun 5 at 20:05












  • @Charles Duffy Ok, thank you. I'm not that used to the terminology about syntactic / literal quotes. But it's very helpful of you elaborate, thank you very much (eventually I'll hopefully learn it)...

    – Okay Dokey
    Jun 6 at 15:26













6












6








6








I have a problem, with this simple script (pick a random file):



#!/usr/bin/env bash
set -x
srcDir="/home/user/Desktop/wallPapers/dir1,dir2,dir3"
randomFile=$(find "$srcDir" -type f -iname "*.jpg" | shuf -n 1)
printf '[%s]n' $randomFile
set +x


The problem is that while I can type this at the command line (and works perfectly fine):



find /home/user/Desktop/wallPapers/dir1,dir2,dir3 -type f -iname "*.jpg"


Then the bash debugging set-commands (set -x and +x) tells me, that for some reason bash both encloses the directory string with single quotation marks and it also replaces the double quotation marks with single quotation marks?



./script.sh
+ srcDir='/home/user/Desktop/wallPapers/dir1,dir2,dir3'
++ find '/home/user/Desktop/wallPapers/dir1,dir2,dir3' -type f -iname '"*.jpg"'
find: ‘/home/user/Desktop/wallPapers/dir1,dir2,dir3’: No such file or directory
+ randomFile=
+ printf '[%s]n'
[]
+ set +x


I understand, this is what bash sees, when the script runs:



find '/home/user/Desktop/wallPapers/dir1,dir2,dir3' -type -iname '*.jpg'


And this causes the "No such file or directory"-message, very very annoying... I do not understand, why it inserts these single quotation marks, I want double quotation marks used instead, just like on the command line... Could anyone please explain, I would be happy for that, thanks!










share|improve this question
















I have a problem, with this simple script (pick a random file):



#!/usr/bin/env bash
set -x
srcDir="/home/user/Desktop/wallPapers/dir1,dir2,dir3"
randomFile=$(find "$srcDir" -type f -iname "*.jpg" | shuf -n 1)
printf '[%s]n' $randomFile
set +x


The problem is that while I can type this at the command line (and works perfectly fine):



find /home/user/Desktop/wallPapers/dir1,dir2,dir3 -type f -iname "*.jpg"


Then the bash debugging set-commands (set -x and +x) tells me, that for some reason bash both encloses the directory string with single quotation marks and it also replaces the double quotation marks with single quotation marks?



./script.sh
+ srcDir='/home/user/Desktop/wallPapers/dir1,dir2,dir3'
++ find '/home/user/Desktop/wallPapers/dir1,dir2,dir3' -type f -iname '"*.jpg"'
find: ‘/home/user/Desktop/wallPapers/dir1,dir2,dir3’: No such file or directory
+ randomFile=
+ printf '[%s]n'
[]
+ set +x


I understand, this is what bash sees, when the script runs:



find '/home/user/Desktop/wallPapers/dir1,dir2,dir3' -type -iname '*.jpg'


And this causes the "No such file or directory"-message, very very annoying... I do not understand, why it inserts these single quotation marks, I want double quotation marks used instead, just like on the command line... Could anyone please explain, I would be happy for that, thanks!







command-line bash scripts






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 5 at 18:44









Charles Duffy

1055




1055










asked Jun 4 at 15:19









Okay DokeyOkay Dokey

6010




6010












  • It's not "*.jpg" that doesn't happen, it's dir1,dir2,dir3.

    – Charles Duffy
    Jun 5 at 15:47











  • Thank you very much. On second thought: Isn't it both? I also don't think '.jpg' expands correctly (if there wasn't a single quotation mark around '.jpg', which was shown from inside the "set -x" and "set +x"-section, I would agree... But I honestly also do not know why bash encloses the directory and the file inside single quotation mark...

    – Okay Dokey
    Jun 5 at 18:48











  • *.jpg, in find . -iname '*.jpg', is parsed by find, not by bash; it's expected that it not be expanded by the shell -- if it were, find would never see it. Thus, having a single layer of syntactic quotes (and no literal quotes) is entirely correct and desired in that case. ("Literal" quotes are quotes that are part of the data, and thus passed to find; "syntactic" quotes are quotes that are part of the shell syntax, and thus consumed by bash itself).

    – Charles Duffy
    Jun 5 at 20:05












  • @Charles Duffy Ok, thank you. I'm not that used to the terminology about syntactic / literal quotes. But it's very helpful of you elaborate, thank you very much (eventually I'll hopefully learn it)...

    – Okay Dokey
    Jun 6 at 15:26

















  • It's not "*.jpg" that doesn't happen, it's dir1,dir2,dir3.

    – Charles Duffy
    Jun 5 at 15:47











  • Thank you very much. On second thought: Isn't it both? I also don't think '.jpg' expands correctly (if there wasn't a single quotation mark around '.jpg', which was shown from inside the "set -x" and "set +x"-section, I would agree... But I honestly also do not know why bash encloses the directory and the file inside single quotation mark...

    – Okay Dokey
    Jun 5 at 18:48











  • *.jpg, in find . -iname '*.jpg', is parsed by find, not by bash; it's expected that it not be expanded by the shell -- if it were, find would never see it. Thus, having a single layer of syntactic quotes (and no literal quotes) is entirely correct and desired in that case. ("Literal" quotes are quotes that are part of the data, and thus passed to find; "syntactic" quotes are quotes that are part of the shell syntax, and thus consumed by bash itself).

    – Charles Duffy
    Jun 5 at 20:05












  • @Charles Duffy Ok, thank you. I'm not that used to the terminology about syntactic / literal quotes. But it's very helpful of you elaborate, thank you very much (eventually I'll hopefully learn it)...

    – Okay Dokey
    Jun 6 at 15:26
















It's not "*.jpg" that doesn't happen, it's dir1,dir2,dir3.

– Charles Duffy
Jun 5 at 15:47





It's not "*.jpg" that doesn't happen, it's dir1,dir2,dir3.

– Charles Duffy
Jun 5 at 15:47













Thank you very much. On second thought: Isn't it both? I also don't think '.jpg' expands correctly (if there wasn't a single quotation mark around '.jpg', which was shown from inside the "set -x" and "set +x"-section, I would agree... But I honestly also do not know why bash encloses the directory and the file inside single quotation mark...

– Okay Dokey
Jun 5 at 18:48





Thank you very much. On second thought: Isn't it both? I also don't think '.jpg' expands correctly (if there wasn't a single quotation mark around '.jpg', which was shown from inside the "set -x" and "set +x"-section, I would agree... But I honestly also do not know why bash encloses the directory and the file inside single quotation mark...

– Okay Dokey
Jun 5 at 18:48













*.jpg, in find . -iname '*.jpg', is parsed by find, not by bash; it's expected that it not be expanded by the shell -- if it were, find would never see it. Thus, having a single layer of syntactic quotes (and no literal quotes) is entirely correct and desired in that case. ("Literal" quotes are quotes that are part of the data, and thus passed to find; "syntactic" quotes are quotes that are part of the shell syntax, and thus consumed by bash itself).

– Charles Duffy
Jun 5 at 20:05






*.jpg, in find . -iname '*.jpg', is parsed by find, not by bash; it's expected that it not be expanded by the shell -- if it were, find would never see it. Thus, having a single layer of syntactic quotes (and no literal quotes) is entirely correct and desired in that case. ("Literal" quotes are quotes that are part of the data, and thus passed to find; "syntactic" quotes are quotes that are part of the shell syntax, and thus consumed by bash itself).

– Charles Duffy
Jun 5 at 20:05














@Charles Duffy Ok, thank you. I'm not that used to the terminology about syntactic / literal quotes. But it's very helpful of you elaborate, thank you very much (eventually I'll hopefully learn it)...

– Okay Dokey
Jun 6 at 15:26





@Charles Duffy Ok, thank you. I'm not that used to the terminology about syntactic / literal quotes. But it's very helpful of you elaborate, thank you very much (eventually I'll hopefully learn it)...

– Okay Dokey
Jun 6 at 15:26










3 Answers
3






active

oldest

votes


















11














Brace expansion doesn't occur within a variable assignment, as explained here:



Why do tilde prefixes expand prior to assignment, but braces don't



In other contexts, the quotes would have prevented brace expansion as well.



Even if you do manage to get srcDir to expand to a list of directories, quoting it again in the find command will cause it to be treated as a single argument instead of 3 separate paths.



Probably the right way to do this in bash is to use an array:



#!/usr/bin/env bash
set -x
srcDir=("/home/user/Desktop/wallPapers/"dir1,dir2,dir3)
randomFile=$(find "$srcDir[@]" -type f -iname "*.jpg" | shuf -n 1)
printf '[%s]n' "$randomFile"
set +x





share|improve this answer

























  • This is exactly the solution I was looking for, thank you very much. You keep using the variables, which I wanted to learn how to use. Also, I didn't realise/knew I had to use an array, now I know in the future. In the top of my script I then define "srcDir" - and then the script does whatever it's supposed to do later on, with the result in the "randomFile"-variable. Thank you very much.

    – Okay Dokey
    Jun 4 at 16:00



















4














As others have already pointed out, the quotes are preventing the brace expansion. You could simplify your script to just:



#!/usr/bin/env bash
printf '[%s]n' "$(find /home/terdon/Desktop/wallPapers/dir1,dir2,dir3 -type f -iname "*.jpg" | shuf -n 1)"


Or, if your file names can contain newline characters:



#!/usr/bin/env bash
printf '[%s]n' "$(find /home/terdon/Desktop/wallPapers/dir1,dir2,dir3 -type f -iname "*.jpg" -print0| shuf -zn 1)"


If you want something that can run on arbitrary directories and file types, try this:



#!/usr/bin/env bash

targetFilePattern="$1"
shift
declare -a targetDirs=("$@")
echo "find $targetDirs[@] -type f -iname '$targetFilePattern' | shuf -n 1"
randomFile=$(find "$targetDirs[@]" -type f -iname "$targetFilePattern" | shuf -n 1)
echo "$randomFile"


You can then run it as:



printRandomFile '*jpg' /home/terdon/Desktop/wallPapers/dir1,dir2,dir3


Or even



printRandomFile '*jpg' /home/terdon/Desktop/wallPapers/dir1,dir2,dir3,'a dir with a space'





share|improve this answer

























  • Thanks - also this looks a bit "hardcoded" - I wanted to have the resulting random file-name in a new variable, so I could keep do some manipulation later on in the script. The prinf was only for myself, to see the value. Sorry, you, couldn't know that, because I didn't tell it before... I'm however upvoting for the good explanation, as my way of saying thanks.

    – Okay Dokey
    Jun 4 at 15:58











  • @OkayDokey if you want it in a variable, just use randomFile="$(find /home/terdon/Desktop/wallPapers/dir1,dir2,dir3 -type f -iname "*.jpg" -print0| shuf -zn 1)"

    – terdon
    Jun 4 at 16:03












  • Yes, ok, I know. But the path is kind of "hard-coded" which is ok for a small script. But you're right. The solutions you presented are all good, thanks.

    – Okay Dokey
    Jun 4 at 16:20











  • @OkayDokey see update for how to make it truly not hardcoded.

    – terdon
    Jun 4 at 17:16











  • Very, very nice, thank you very much, this is also (more of) what I was looking for...

    – Okay Dokey
    Jun 5 at 18:50



















3














Brace expansion isnt performed inside double quotes. There is a duplicate question regarding this somewhere. Also, use -printf flag for find, doing command substitution is unnecessary, so you can do this



find /home/user/Desktop/wallPapers/dir1,dir2,dir3 -type f -iname "*.jpg" -printf '[%f]n' | shuf -n1





share|improve this answer

























  • This breaks in the unlikely case where the file names contain newlines.

    – terdon
    Jun 4 at 15:50











  • Fair point, -print0 is better for those cases

    – Sergiy Kolodyazhnyy
    Jun 4 at 15:52











  • Thank you very much, but for a script that could eventually become bigger I prefer executing some kind of expression, based on variables, defined in the top of the script. This looks a bit more like something on the command line - but I upvoted, due to the explanation. The purpose of my script was also not to just print something out on the screen (the printf-line) - but to do some further manipulation. I know you couldn't see that from my original post, so sorry about that... And thanks.

    – Okay Dokey
    Jun 4 at 15:56











  • @OkayDokey you seem to be misunderstanding. This (and all other answers so far) are no more "hardcoded" than your approach. But perhaps we can give you better solutions if you edit your question and explain in more detail.

    – terdon
    Jun 4 at 16:06











  • @OkayDokey If you do need to use dir1,dir2,dir3 later in a script, use set command or array to save the directory names. I would explain further but currently have no time. And yes, it was not obvious that you want to reuse those further.

    – Sergiy Kolodyazhnyy
    Jun 4 at 16:13













Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1148573%2fbash-script-dir1-dir2-dir3-expansion-not-working-as-expected-from-variable-f%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









11














Brace expansion doesn't occur within a variable assignment, as explained here:



Why do tilde prefixes expand prior to assignment, but braces don't



In other contexts, the quotes would have prevented brace expansion as well.



Even if you do manage to get srcDir to expand to a list of directories, quoting it again in the find command will cause it to be treated as a single argument instead of 3 separate paths.



Probably the right way to do this in bash is to use an array:



#!/usr/bin/env bash
set -x
srcDir=("/home/user/Desktop/wallPapers/"dir1,dir2,dir3)
randomFile=$(find "$srcDir[@]" -type f -iname "*.jpg" | shuf -n 1)
printf '[%s]n' "$randomFile"
set +x





share|improve this answer

























  • This is exactly the solution I was looking for, thank you very much. You keep using the variables, which I wanted to learn how to use. Also, I didn't realise/knew I had to use an array, now I know in the future. In the top of my script I then define "srcDir" - and then the script does whatever it's supposed to do later on, with the result in the "randomFile"-variable. Thank you very much.

    – Okay Dokey
    Jun 4 at 16:00
















11














Brace expansion doesn't occur within a variable assignment, as explained here:



Why do tilde prefixes expand prior to assignment, but braces don't



In other contexts, the quotes would have prevented brace expansion as well.



Even if you do manage to get srcDir to expand to a list of directories, quoting it again in the find command will cause it to be treated as a single argument instead of 3 separate paths.



Probably the right way to do this in bash is to use an array:



#!/usr/bin/env bash
set -x
srcDir=("/home/user/Desktop/wallPapers/"dir1,dir2,dir3)
randomFile=$(find "$srcDir[@]" -type f -iname "*.jpg" | shuf -n 1)
printf '[%s]n' "$randomFile"
set +x





share|improve this answer

























  • This is exactly the solution I was looking for, thank you very much. You keep using the variables, which I wanted to learn how to use. Also, I didn't realise/knew I had to use an array, now I know in the future. In the top of my script I then define "srcDir" - and then the script does whatever it's supposed to do later on, with the result in the "randomFile"-variable. Thank you very much.

    – Okay Dokey
    Jun 4 at 16:00














11












11








11







Brace expansion doesn't occur within a variable assignment, as explained here:



Why do tilde prefixes expand prior to assignment, but braces don't



In other contexts, the quotes would have prevented brace expansion as well.



Even if you do manage to get srcDir to expand to a list of directories, quoting it again in the find command will cause it to be treated as a single argument instead of 3 separate paths.



Probably the right way to do this in bash is to use an array:



#!/usr/bin/env bash
set -x
srcDir=("/home/user/Desktop/wallPapers/"dir1,dir2,dir3)
randomFile=$(find "$srcDir[@]" -type f -iname "*.jpg" | shuf -n 1)
printf '[%s]n' "$randomFile"
set +x





share|improve this answer















Brace expansion doesn't occur within a variable assignment, as explained here:



Why do tilde prefixes expand prior to assignment, but braces don't



In other contexts, the quotes would have prevented brace expansion as well.



Even if you do manage to get srcDir to expand to a list of directories, quoting it again in the find command will cause it to be treated as a single argument instead of 3 separate paths.



Probably the right way to do this in bash is to use an array:



#!/usr/bin/env bash
set -x
srcDir=("/home/user/Desktop/wallPapers/"dir1,dir2,dir3)
randomFile=$(find "$srcDir[@]" -type f -iname "*.jpg" | shuf -n 1)
printf '[%s]n' "$randomFile"
set +x






share|improve this answer














share|improve this answer



share|improve this answer








edited Jun 4 at 15:44

























answered Jun 4 at 15:39









steeldriversteeldriver

74.2k11122200




74.2k11122200












  • This is exactly the solution I was looking for, thank you very much. You keep using the variables, which I wanted to learn how to use. Also, I didn't realise/knew I had to use an array, now I know in the future. In the top of my script I then define "srcDir" - and then the script does whatever it's supposed to do later on, with the result in the "randomFile"-variable. Thank you very much.

    – Okay Dokey
    Jun 4 at 16:00


















  • This is exactly the solution I was looking for, thank you very much. You keep using the variables, which I wanted to learn how to use. Also, I didn't realise/knew I had to use an array, now I know in the future. In the top of my script I then define "srcDir" - and then the script does whatever it's supposed to do later on, with the result in the "randomFile"-variable. Thank you very much.

    – Okay Dokey
    Jun 4 at 16:00

















This is exactly the solution I was looking for, thank you very much. You keep using the variables, which I wanted to learn how to use. Also, I didn't realise/knew I had to use an array, now I know in the future. In the top of my script I then define "srcDir" - and then the script does whatever it's supposed to do later on, with the result in the "randomFile"-variable. Thank you very much.

– Okay Dokey
Jun 4 at 16:00






This is exactly the solution I was looking for, thank you very much. You keep using the variables, which I wanted to learn how to use. Also, I didn't realise/knew I had to use an array, now I know in the future. In the top of my script I then define "srcDir" - and then the script does whatever it's supposed to do later on, with the result in the "randomFile"-variable. Thank you very much.

– Okay Dokey
Jun 4 at 16:00














4














As others have already pointed out, the quotes are preventing the brace expansion. You could simplify your script to just:



#!/usr/bin/env bash
printf '[%s]n' "$(find /home/terdon/Desktop/wallPapers/dir1,dir2,dir3 -type f -iname "*.jpg" | shuf -n 1)"


Or, if your file names can contain newline characters:



#!/usr/bin/env bash
printf '[%s]n' "$(find /home/terdon/Desktop/wallPapers/dir1,dir2,dir3 -type f -iname "*.jpg" -print0| shuf -zn 1)"


If you want something that can run on arbitrary directories and file types, try this:



#!/usr/bin/env bash

targetFilePattern="$1"
shift
declare -a targetDirs=("$@")
echo "find $targetDirs[@] -type f -iname '$targetFilePattern' | shuf -n 1"
randomFile=$(find "$targetDirs[@]" -type f -iname "$targetFilePattern" | shuf -n 1)
echo "$randomFile"


You can then run it as:



printRandomFile '*jpg' /home/terdon/Desktop/wallPapers/dir1,dir2,dir3


Or even



printRandomFile '*jpg' /home/terdon/Desktop/wallPapers/dir1,dir2,dir3,'a dir with a space'





share|improve this answer

























  • Thanks - also this looks a bit "hardcoded" - I wanted to have the resulting random file-name in a new variable, so I could keep do some manipulation later on in the script. The prinf was only for myself, to see the value. Sorry, you, couldn't know that, because I didn't tell it before... I'm however upvoting for the good explanation, as my way of saying thanks.

    – Okay Dokey
    Jun 4 at 15:58











  • @OkayDokey if you want it in a variable, just use randomFile="$(find /home/terdon/Desktop/wallPapers/dir1,dir2,dir3 -type f -iname "*.jpg" -print0| shuf -zn 1)"

    – terdon
    Jun 4 at 16:03












  • Yes, ok, I know. But the path is kind of "hard-coded" which is ok for a small script. But you're right. The solutions you presented are all good, thanks.

    – Okay Dokey
    Jun 4 at 16:20











  • @OkayDokey see update for how to make it truly not hardcoded.

    – terdon
    Jun 4 at 17:16











  • Very, very nice, thank you very much, this is also (more of) what I was looking for...

    – Okay Dokey
    Jun 5 at 18:50
















4














As others have already pointed out, the quotes are preventing the brace expansion. You could simplify your script to just:



#!/usr/bin/env bash
printf '[%s]n' "$(find /home/terdon/Desktop/wallPapers/dir1,dir2,dir3 -type f -iname "*.jpg" | shuf -n 1)"


Or, if your file names can contain newline characters:



#!/usr/bin/env bash
printf '[%s]n' "$(find /home/terdon/Desktop/wallPapers/dir1,dir2,dir3 -type f -iname "*.jpg" -print0| shuf -zn 1)"


If you want something that can run on arbitrary directories and file types, try this:



#!/usr/bin/env bash

targetFilePattern="$1"
shift
declare -a targetDirs=("$@")
echo "find $targetDirs[@] -type f -iname '$targetFilePattern' | shuf -n 1"
randomFile=$(find "$targetDirs[@]" -type f -iname "$targetFilePattern" | shuf -n 1)
echo "$randomFile"


You can then run it as:



printRandomFile '*jpg' /home/terdon/Desktop/wallPapers/dir1,dir2,dir3


Or even



printRandomFile '*jpg' /home/terdon/Desktop/wallPapers/dir1,dir2,dir3,'a dir with a space'





share|improve this answer

























  • Thanks - also this looks a bit "hardcoded" - I wanted to have the resulting random file-name in a new variable, so I could keep do some manipulation later on in the script. The prinf was only for myself, to see the value. Sorry, you, couldn't know that, because I didn't tell it before... I'm however upvoting for the good explanation, as my way of saying thanks.

    – Okay Dokey
    Jun 4 at 15:58











  • @OkayDokey if you want it in a variable, just use randomFile="$(find /home/terdon/Desktop/wallPapers/dir1,dir2,dir3 -type f -iname "*.jpg" -print0| shuf -zn 1)"

    – terdon
    Jun 4 at 16:03












  • Yes, ok, I know. But the path is kind of "hard-coded" which is ok for a small script. But you're right. The solutions you presented are all good, thanks.

    – Okay Dokey
    Jun 4 at 16:20











  • @OkayDokey see update for how to make it truly not hardcoded.

    – terdon
    Jun 4 at 17:16











  • Very, very nice, thank you very much, this is also (more of) what I was looking for...

    – Okay Dokey
    Jun 5 at 18:50














4












4








4







As others have already pointed out, the quotes are preventing the brace expansion. You could simplify your script to just:



#!/usr/bin/env bash
printf '[%s]n' "$(find /home/terdon/Desktop/wallPapers/dir1,dir2,dir3 -type f -iname "*.jpg" | shuf -n 1)"


Or, if your file names can contain newline characters:



#!/usr/bin/env bash
printf '[%s]n' "$(find /home/terdon/Desktop/wallPapers/dir1,dir2,dir3 -type f -iname "*.jpg" -print0| shuf -zn 1)"


If you want something that can run on arbitrary directories and file types, try this:



#!/usr/bin/env bash

targetFilePattern="$1"
shift
declare -a targetDirs=("$@")
echo "find $targetDirs[@] -type f -iname '$targetFilePattern' | shuf -n 1"
randomFile=$(find "$targetDirs[@]" -type f -iname "$targetFilePattern" | shuf -n 1)
echo "$randomFile"


You can then run it as:



printRandomFile '*jpg' /home/terdon/Desktop/wallPapers/dir1,dir2,dir3


Or even



printRandomFile '*jpg' /home/terdon/Desktop/wallPapers/dir1,dir2,dir3,'a dir with a space'





share|improve this answer















As others have already pointed out, the quotes are preventing the brace expansion. You could simplify your script to just:



#!/usr/bin/env bash
printf '[%s]n' "$(find /home/terdon/Desktop/wallPapers/dir1,dir2,dir3 -type f -iname "*.jpg" | shuf -n 1)"


Or, if your file names can contain newline characters:



#!/usr/bin/env bash
printf '[%s]n' "$(find /home/terdon/Desktop/wallPapers/dir1,dir2,dir3 -type f -iname "*.jpg" -print0| shuf -zn 1)"


If you want something that can run on arbitrary directories and file types, try this:



#!/usr/bin/env bash

targetFilePattern="$1"
shift
declare -a targetDirs=("$@")
echo "find $targetDirs[@] -type f -iname '$targetFilePattern' | shuf -n 1"
randomFile=$(find "$targetDirs[@]" -type f -iname "$targetFilePattern" | shuf -n 1)
echo "$randomFile"


You can then run it as:



printRandomFile '*jpg' /home/terdon/Desktop/wallPapers/dir1,dir2,dir3


Or even



printRandomFile '*jpg' /home/terdon/Desktop/wallPapers/dir1,dir2,dir3,'a dir with a space'






share|improve this answer














share|improve this answer



share|improve this answer








edited Jun 4 at 17:15

























answered Jun 4 at 15:46









terdonterdon

70.7k13148231




70.7k13148231












  • Thanks - also this looks a bit "hardcoded" - I wanted to have the resulting random file-name in a new variable, so I could keep do some manipulation later on in the script. The prinf was only for myself, to see the value. Sorry, you, couldn't know that, because I didn't tell it before... I'm however upvoting for the good explanation, as my way of saying thanks.

    – Okay Dokey
    Jun 4 at 15:58











  • @OkayDokey if you want it in a variable, just use randomFile="$(find /home/terdon/Desktop/wallPapers/dir1,dir2,dir3 -type f -iname "*.jpg" -print0| shuf -zn 1)"

    – terdon
    Jun 4 at 16:03












  • Yes, ok, I know. But the path is kind of "hard-coded" which is ok for a small script. But you're right. The solutions you presented are all good, thanks.

    – Okay Dokey
    Jun 4 at 16:20











  • @OkayDokey see update for how to make it truly not hardcoded.

    – terdon
    Jun 4 at 17:16











  • Very, very nice, thank you very much, this is also (more of) what I was looking for...

    – Okay Dokey
    Jun 5 at 18:50


















  • Thanks - also this looks a bit "hardcoded" - I wanted to have the resulting random file-name in a new variable, so I could keep do some manipulation later on in the script. The prinf was only for myself, to see the value. Sorry, you, couldn't know that, because I didn't tell it before... I'm however upvoting for the good explanation, as my way of saying thanks.

    – Okay Dokey
    Jun 4 at 15:58











  • @OkayDokey if you want it in a variable, just use randomFile="$(find /home/terdon/Desktop/wallPapers/dir1,dir2,dir3 -type f -iname "*.jpg" -print0| shuf -zn 1)"

    – terdon
    Jun 4 at 16:03












  • Yes, ok, I know. But the path is kind of "hard-coded" which is ok for a small script. But you're right. The solutions you presented are all good, thanks.

    – Okay Dokey
    Jun 4 at 16:20











  • @OkayDokey see update for how to make it truly not hardcoded.

    – terdon
    Jun 4 at 17:16











  • Very, very nice, thank you very much, this is also (more of) what I was looking for...

    – Okay Dokey
    Jun 5 at 18:50

















Thanks - also this looks a bit "hardcoded" - I wanted to have the resulting random file-name in a new variable, so I could keep do some manipulation later on in the script. The prinf was only for myself, to see the value. Sorry, you, couldn't know that, because I didn't tell it before... I'm however upvoting for the good explanation, as my way of saying thanks.

– Okay Dokey
Jun 4 at 15:58





Thanks - also this looks a bit "hardcoded" - I wanted to have the resulting random file-name in a new variable, so I could keep do some manipulation later on in the script. The prinf was only for myself, to see the value. Sorry, you, couldn't know that, because I didn't tell it before... I'm however upvoting for the good explanation, as my way of saying thanks.

– Okay Dokey
Jun 4 at 15:58













@OkayDokey if you want it in a variable, just use randomFile="$(find /home/terdon/Desktop/wallPapers/dir1,dir2,dir3 -type f -iname "*.jpg" -print0| shuf -zn 1)"

– terdon
Jun 4 at 16:03






@OkayDokey if you want it in a variable, just use randomFile="$(find /home/terdon/Desktop/wallPapers/dir1,dir2,dir3 -type f -iname "*.jpg" -print0| shuf -zn 1)"

– terdon
Jun 4 at 16:03














Yes, ok, I know. But the path is kind of "hard-coded" which is ok for a small script. But you're right. The solutions you presented are all good, thanks.

– Okay Dokey
Jun 4 at 16:20





Yes, ok, I know. But the path is kind of "hard-coded" which is ok for a small script. But you're right. The solutions you presented are all good, thanks.

– Okay Dokey
Jun 4 at 16:20













@OkayDokey see update for how to make it truly not hardcoded.

– terdon
Jun 4 at 17:16





@OkayDokey see update for how to make it truly not hardcoded.

– terdon
Jun 4 at 17:16













Very, very nice, thank you very much, this is also (more of) what I was looking for...

– Okay Dokey
Jun 5 at 18:50






Very, very nice, thank you very much, this is also (more of) what I was looking for...

– Okay Dokey
Jun 5 at 18:50












3














Brace expansion isnt performed inside double quotes. There is a duplicate question regarding this somewhere. Also, use -printf flag for find, doing command substitution is unnecessary, so you can do this



find /home/user/Desktop/wallPapers/dir1,dir2,dir3 -type f -iname "*.jpg" -printf '[%f]n' | shuf -n1





share|improve this answer

























  • This breaks in the unlikely case where the file names contain newlines.

    – terdon
    Jun 4 at 15:50











  • Fair point, -print0 is better for those cases

    – Sergiy Kolodyazhnyy
    Jun 4 at 15:52











  • Thank you very much, but for a script that could eventually become bigger I prefer executing some kind of expression, based on variables, defined in the top of the script. This looks a bit more like something on the command line - but I upvoted, due to the explanation. The purpose of my script was also not to just print something out on the screen (the printf-line) - but to do some further manipulation. I know you couldn't see that from my original post, so sorry about that... And thanks.

    – Okay Dokey
    Jun 4 at 15:56











  • @OkayDokey you seem to be misunderstanding. This (and all other answers so far) are no more "hardcoded" than your approach. But perhaps we can give you better solutions if you edit your question and explain in more detail.

    – terdon
    Jun 4 at 16:06











  • @OkayDokey If you do need to use dir1,dir2,dir3 later in a script, use set command or array to save the directory names. I would explain further but currently have no time. And yes, it was not obvious that you want to reuse those further.

    – Sergiy Kolodyazhnyy
    Jun 4 at 16:13















3














Brace expansion isnt performed inside double quotes. There is a duplicate question regarding this somewhere. Also, use -printf flag for find, doing command substitution is unnecessary, so you can do this



find /home/user/Desktop/wallPapers/dir1,dir2,dir3 -type f -iname "*.jpg" -printf '[%f]n' | shuf -n1





share|improve this answer

























  • This breaks in the unlikely case where the file names contain newlines.

    – terdon
    Jun 4 at 15:50











  • Fair point, -print0 is better for those cases

    – Sergiy Kolodyazhnyy
    Jun 4 at 15:52











  • Thank you very much, but for a script that could eventually become bigger I prefer executing some kind of expression, based on variables, defined in the top of the script. This looks a bit more like something on the command line - but I upvoted, due to the explanation. The purpose of my script was also not to just print something out on the screen (the printf-line) - but to do some further manipulation. I know you couldn't see that from my original post, so sorry about that... And thanks.

    – Okay Dokey
    Jun 4 at 15:56











  • @OkayDokey you seem to be misunderstanding. This (and all other answers so far) are no more "hardcoded" than your approach. But perhaps we can give you better solutions if you edit your question and explain in more detail.

    – terdon
    Jun 4 at 16:06











  • @OkayDokey If you do need to use dir1,dir2,dir3 later in a script, use set command or array to save the directory names. I would explain further but currently have no time. And yes, it was not obvious that you want to reuse those further.

    – Sergiy Kolodyazhnyy
    Jun 4 at 16:13













3












3








3







Brace expansion isnt performed inside double quotes. There is a duplicate question regarding this somewhere. Also, use -printf flag for find, doing command substitution is unnecessary, so you can do this



find /home/user/Desktop/wallPapers/dir1,dir2,dir3 -type f -iname "*.jpg" -printf '[%f]n' | shuf -n1





share|improve this answer















Brace expansion isnt performed inside double quotes. There is a duplicate question regarding this somewhere. Also, use -printf flag for find, doing command substitution is unnecessary, so you can do this



find /home/user/Desktop/wallPapers/dir1,dir2,dir3 -type f -iname "*.jpg" -printf '[%f]n' | shuf -n1






share|improve this answer














share|improve this answer



share|improve this answer








edited Jun 4 at 15:49









terdon

70.7k13148231




70.7k13148231










answered Jun 4 at 15:39









Sergiy KolodyazhnyySergiy Kolodyazhnyy

76.9k10162340




76.9k10162340












  • This breaks in the unlikely case where the file names contain newlines.

    – terdon
    Jun 4 at 15:50











  • Fair point, -print0 is better for those cases

    – Sergiy Kolodyazhnyy
    Jun 4 at 15:52











  • Thank you very much, but for a script that could eventually become bigger I prefer executing some kind of expression, based on variables, defined in the top of the script. This looks a bit more like something on the command line - but I upvoted, due to the explanation. The purpose of my script was also not to just print something out on the screen (the printf-line) - but to do some further manipulation. I know you couldn't see that from my original post, so sorry about that... And thanks.

    – Okay Dokey
    Jun 4 at 15:56











  • @OkayDokey you seem to be misunderstanding. This (and all other answers so far) are no more "hardcoded" than your approach. But perhaps we can give you better solutions if you edit your question and explain in more detail.

    – terdon
    Jun 4 at 16:06











  • @OkayDokey If you do need to use dir1,dir2,dir3 later in a script, use set command or array to save the directory names. I would explain further but currently have no time. And yes, it was not obvious that you want to reuse those further.

    – Sergiy Kolodyazhnyy
    Jun 4 at 16:13

















  • This breaks in the unlikely case where the file names contain newlines.

    – terdon
    Jun 4 at 15:50











  • Fair point, -print0 is better for those cases

    – Sergiy Kolodyazhnyy
    Jun 4 at 15:52











  • Thank you very much, but for a script that could eventually become bigger I prefer executing some kind of expression, based on variables, defined in the top of the script. This looks a bit more like something on the command line - but I upvoted, due to the explanation. The purpose of my script was also not to just print something out on the screen (the printf-line) - but to do some further manipulation. I know you couldn't see that from my original post, so sorry about that... And thanks.

    – Okay Dokey
    Jun 4 at 15:56











  • @OkayDokey you seem to be misunderstanding. This (and all other answers so far) are no more "hardcoded" than your approach. But perhaps we can give you better solutions if you edit your question and explain in more detail.

    – terdon
    Jun 4 at 16:06











  • @OkayDokey If you do need to use dir1,dir2,dir3 later in a script, use set command or array to save the directory names. I would explain further but currently have no time. And yes, it was not obvious that you want to reuse those further.

    – Sergiy Kolodyazhnyy
    Jun 4 at 16:13
















This breaks in the unlikely case where the file names contain newlines.

– terdon
Jun 4 at 15:50





This breaks in the unlikely case where the file names contain newlines.

– terdon
Jun 4 at 15:50













Fair point, -print0 is better for those cases

– Sergiy Kolodyazhnyy
Jun 4 at 15:52





Fair point, -print0 is better for those cases

– Sergiy Kolodyazhnyy
Jun 4 at 15:52













Thank you very much, but for a script that could eventually become bigger I prefer executing some kind of expression, based on variables, defined in the top of the script. This looks a bit more like something on the command line - but I upvoted, due to the explanation. The purpose of my script was also not to just print something out on the screen (the printf-line) - but to do some further manipulation. I know you couldn't see that from my original post, so sorry about that... And thanks.

– Okay Dokey
Jun 4 at 15:56





Thank you very much, but for a script that could eventually become bigger I prefer executing some kind of expression, based on variables, defined in the top of the script. This looks a bit more like something on the command line - but I upvoted, due to the explanation. The purpose of my script was also not to just print something out on the screen (the printf-line) - but to do some further manipulation. I know you couldn't see that from my original post, so sorry about that... And thanks.

– Okay Dokey
Jun 4 at 15:56













@OkayDokey you seem to be misunderstanding. This (and all other answers so far) are no more "hardcoded" than your approach. But perhaps we can give you better solutions if you edit your question and explain in more detail.

– terdon
Jun 4 at 16:06





@OkayDokey you seem to be misunderstanding. This (and all other answers so far) are no more "hardcoded" than your approach. But perhaps we can give you better solutions if you edit your question and explain in more detail.

– terdon
Jun 4 at 16:06













@OkayDokey If you do need to use dir1,dir2,dir3 later in a script, use set command or array to save the directory names. I would explain further but currently have no time. And yes, it was not obvious that you want to reuse those further.

– Sergiy Kolodyazhnyy
Jun 4 at 16:13





@OkayDokey If you do need to use dir1,dir2,dir3 later in a script, use set command or array to save the directory names. I would explain further but currently have no time. And yes, it was not obvious that you want to reuse those further.

– Sergiy Kolodyazhnyy
Jun 4 at 16:13

















draft saved

draft discarded
















































Thanks for contributing an answer to Ask Ubuntu!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1148573%2fbash-script-dir1-dir2-dir3-expansion-not-working-as-expected-from-variable-f%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Club Baloncesto Breogán Índice Historia | Pavillón | Nome | O Breogán na cultura popular | Xogadores | Adestradores | Presidentes | Palmarés | Historial | Líderes | Notas | Véxase tamén | Menú de navegacióncbbreogan.galCadroGuía oficial da ACB 2009-10, páxina 201Guía oficial ACB 1992, páxina 183. Editorial DB.É de 6.500 espectadores sentados axeitándose á última normativa"Estudiantes Junior, entre as mellores canteiras"o orixinalHemeroteca El Mundo Deportivo, 16 setembro de 1970, páxina 12Historia do BreogánAlfredo Pérez, o último canoneiroHistoria C.B. BreogánHemeroteca de El Mundo DeportivoJimmy Wright, norteamericano do Breogán deixará Lugo por ameazas de morteResultados de Breogán en 1986-87Resultados de Breogán en 1990-91Ficha de Velimir Perasović en acb.comResultados de Breogán en 1994-95Breogán arrasa al Barça. "El Mundo Deportivo", 27 de setembro de 1999, páxina 58CB Breogán - FC BarcelonaA FEB invita a participar nunha nova Liga EuropeaCharlie Bell na prensa estatalMáximos anotadores 2005Tempada 2005-06 : Tódolos Xogadores da Xornada""Non quero pensar nunha man negra, mais pregúntome que está a pasar""o orixinalRaúl López, orgulloso dos xogadores, presume da boa saúde económica do BreogánJulio González confirma que cesa como presidente del BreogánHomenaxe a Lisardo GómezA tempada do rexurdimento celesteEntrevista a Lisardo GómezEl COB dinamita el Pazo para forzar el quinto (69-73)Cafés Candelas, patrocinador del CB Breogán"Suso Lázare, novo presidente do Breogán"o orixinalCafés Candelas Breogán firma el mayor triunfo de la historiaEl Breogán realizará 17 homenajes por su cincuenta aniversario"O Breogán honra ao seu fundador e primeiro presidente"o orixinalMiguel Giao recibiu a homenaxe do PazoHomenaxe aos primeiros gladiadores celestesO home que nos amosa como ver o Breo co corazónTita Franco será homenaxeada polos #50anosdeBreoJulio Vila recibirá unha homenaxe in memoriam polos #50anosdeBreo"O Breogán homenaxeará aos seus aboados máis veteráns"Pechada ovación a «Capi» Sanmartín e Ricardo «Corazón de González»Homenaxe por décadas de informaciónPaco García volve ao Pazo con motivo do 50 aniversario"Resultados y clasificaciones""O Cafés Candelas Breogán, campión da Copa Princesa""O Cafés Candelas Breogán, equipo ACB"C.B. Breogán"Proxecto social"o orixinal"Centros asociados"o orixinalFicha en imdb.comMario Camus trata la recuperación del amor en 'La vieja música', su última película"Páxina web oficial""Club Baloncesto Breogán""C. B. Breogán S.A.D."eehttp://www.fegaba.com

Vilaño, A Laracha Índice Patrimonio | Lugares e parroquias | Véxase tamén | Menú de navegación43°14′52″N 8°36′03″O / 43.24775, -8.60070

Cegueira Índice Epidemioloxía | Deficiencia visual | Tipos de cegueira | Principais causas de cegueira | Tratamento | Técnicas de adaptación e axudas | Vida dos cegos | Primeiros auxilios | Crenzas respecto das persoas cegas | Crenzas das persoas cegas | O neno deficiente visual | Aspectos psicolóxicos da cegueira | Notas | Véxase tamén | Menú de navegación54.054.154.436928256blindnessDicionario da Real Academia GalegaPortal das Palabras"International Standards: Visual Standards — Aspects and Ranges of Vision Loss with Emphasis on Population Surveys.""Visual impairment and blindness""Presentan un plan para previr a cegueira"o orixinalACCDV Associació Catalana de Cecs i Disminuïts Visuals - PMFTrachoma"Effect of gene therapy on visual function in Leber's congenital amaurosis"1844137110.1056/NEJMoa0802268Cans guía - os mellores amigos dos cegosArquivadoEscola de cans guía para cegos en Mortágua, PortugalArquivado"Tecnología para ciegos y deficientes visuales. Recopilación de recursos gratuitos en la Red""Colorino""‘COL.diesis’, escuchar los sonidos del color""COL.diesis: Transforming Colour into Melody and Implementing the Result in a Colour Sensor Device"o orixinal"Sistema de desarrollo de sinestesia color-sonido para invidentes utilizando un protocolo de audio""Enseñanza táctil - geometría y color. Juegos didácticos para niños ciegos y videntes""Sistema Constanz"L'ocupació laboral dels cecs a l'Estat espanyol està pràcticament equiparada a la de les persones amb visió, entrevista amb Pedro ZuritaONCE (Organización Nacional de Cegos de España)Prevención da cegueiraDescrición de deficiencias visuais (Disc@pnet)Braillín, un boneco atractivo para calquera neno, con ou sen discapacidade, que permite familiarizarse co sistema de escritura e lectura brailleAxudas Técnicas36838ID00897494007150-90057129528256DOID:1432HP:0000618D001766C10.597.751.941.162C97109C0155020