<p>I need to rearrange some content in various directories but it's a bit of a pain. In order to debug the application I'm working on (a ruby app) I need to move my gems into my gem folder one at a time (long story; nutshell: one is broken and I can't figure out which one).</p>

<p>So I need to do something like:</p>

<pre><code>sudo mv backup/gem/foo gem/
sudo mv backup/doc/foo doc/
sudo mv backup/specification/foo.gemspec specification/
</code></pre>

<p>replacing "foo" each time. How can I author a simple shell script to let me do something like: gemMove("foo") and it fill in the blanks for me?</p>

[{'answer_id': 74920, 'author': 'pjz', 'author_id': 8002, 'author_profile': 'https://Stackoverflow.com/users/8002', 'pm_score': 4, 'selected': True, 'text': '<p>Put the following into a file named <code>gemmove</code>:</p>\n<pre><code>#!/bin/bash\n\nif [ &quot;x$1&quot; == x ]; then\n  echo &quot;Must have an arg&quot;\n  exit 1\nfi\n\nfor d in gem doc specification ; do \n  mv &quot;backup/$d/$1&quot; &quot;$d&quot;\ndone\n</code></pre>\n<p>then do</p>\n<pre><code>chmod a+x gemmove\n</code></pre>\n<p>and then call <code>sudo /path/to/gemmove foo</code> to move the foo gem from the backup dirs into the real ones</p>\n'}, {'answer_id': 74937, 'author': 'sirprize', 'author_id': 12902, 'author_profile': 'https://Stackoverflow.com/users/12902', 'pm_score': 1, 'selected': False, 'text': '<p>You could simply use the bash shell arguments, like this:</p>\n\n<pre><code>#!/bin/bash\n# This is move.sh\nmv backup/gem/$1 gem/\nmv backup/doc/$1 doc/\n# ...\n</code></pre>\n\n<p>and then execute it as:</p>\n\n<pre><code>sudo ./move.sh foo\n</code></pre>\n\n<p>Be sure make the script executable, with</p>\n\n<pre><code>chmod +x move.sh\n</code></pre>\n'}, {'answer_id': 74995, 'author': 'catfood', 'author_id': 12802, 'author_profile': 'https://Stackoverflow.com/users/12802', 'pm_score': 1, 'selected': False, 'text': '<p>in bash, something like:</p>\n\n<pre><code>function gemMove()\n{\nfilename=$1\n   mv backup/gem/$filename gem/$filename\n   mv backup/doc/$filename doc/$filename\n   mv backup/specification/$filename.spec specification\n}\n</code></pre>\n\n<p>then you can just call <code>gemMove("foo")</code> elsewhere in the script.</p>\n'}]
['https://Stackoverflow.com/questions/74886', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/10071/']