Speak now
Please Wait Image Converting Into Text...
Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Challenge yourself and boost your learning! Start the quiz now to earn credits.
Unlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
Course Queries Syllabus Queries 2 years ago
Posted on 16 Aug 2022, this text provides information on Syllabus Queries related to Course Queries. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.
Turn Your Knowledge into Earnings.
I'm using rsync to copy specific files from a source directory (and subdirectories) to a destination directory (and subdirectories). The mapping of the subdirectories is not identical, so I'm defining arrays of subdirectories of the destination directory that contain the source file paths.
I've been unable to successfully loop over the destination arrays with access to the names of the arrays. Here's a MWE (filenames and directories must be edited, obviously).
#!/bin/bash sourcedir=~/Dropbox/230/ destdir=~/Dropbox/230/website/ # Destination arrays organization=( syllabus/syllabus.pdf ) notes=( notes/ME230_2014S_Part0_Lec00.pdf notes/ME230_2014S_Part1_Lec01_partial.pdf ) echo "synchronizing: rsyncing from $sourcedir to $destdir" for destsubdir in $organization $notes do for sourcesubdir in "${destsubdir[@]}" do echo "from $sourcedir$sourcesubdir to $destdir$destsubdir/" rsync -avz "$sourcedir$sourcesubdir" "$destdir$destsubdir/" done done
This is obviously wrong because I don't want the destination to be the contents of $destsubdir but the name of the variable itself. I've been unable to successfully achieve this.
$destsubdir
Note that a proper solution would allow any number of arrays to included without restructuring (e.g. no extra for-loops).
If multi-indexed arrays were possible in bash, this would be much easier, I think. Thanks for any help!
@jeanrjc has a good solution. Here's what it looks like in terms of my example above.
#!/bin/bash sourcedir=~/Dropbox/230/ destdir=~/Dropbox/230/website/ # Destination arrays organization=( syllabus/syllabus.pdf ) notes=( notes/ME230_2014S_Part0_Lec00.pdf notes/ME230_2014S_Part1_Lec01_partial.pdf ) destsubdirArray=( organization notes ) echo "synchronizing: rsyncing from $sourcedir to $destdir" for destsubdir in ${destsubdirArray[*]} do destsubdirContents=$destsubdir[@]; for sourcesubdir in ${!destsubdirContents} do echo "from $sourcedir$sourcesubdir to $destdir$destsubdir/" rsync -avz "$sourcedir$sourcesubdir" "$destdir$destsubdir/" done done
I'm not sure I get what you meant, but maybe this can help you :
one=( "one" 5 6 7 8 ) two=( "two" 11 22 33 ) three=( "tree" 777 888 999 ) all=( one two three ) for i in ${all[*]}; do ref=$i[@]; for j in ${!ref}; do echo $j done done one 5 6 7 8 two 11 22 33 tree 777 888 999
No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
Course Queries 4 Answers
Course Queries 5 Answers
Course Queries 1 Answers
Course Queries 3 Answers
Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.