LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   What does cd $(ls -d *) command do? (https://www.linuxquestions.org/questions/linux-newbie-8/what-does-cd-%24-ls-d-%2A-command-do-4175513058/)

ksy2011s 08-02-2014 02:44 AM

What does cd $(ls -d *) command do?
 
Dear All,

I'm very new in Linux OS, recently, I was try to understand one shell script, there I found one command "cd $(ls -d *)" can you please explain the command?
Thanks in advance.

jwiggins 08-02-2014 10:43 AM

answer
 
well, the $( ... ) means to execute this command first; ls -d * shows a listing of every file and, if it's a directory, only show the directory name and not what is inside the directory (that's what the -d does), so what the command does in the script is it finds the first directory and enters it I'm guessing to do commands inside. If that helps any.

Firerat 08-02-2014 11:04 AM

Stop using that script, it is poorly written

That little bit of 'code' only works if a single directory in the current dir.

Post the script so we can fix it, or point out alternatives


All times are GMT -5. The time now is 03:22 PM.