Bash Script to rename file inside a directory - bash

I have a file named syscheck.sh in /system/0211/ and I want to rename it to checkone.sh.
How can I do it?

To do a rename in a bash script, you simply need to use the mv (move) command.
mv /system/0211/syscheck.sh /system/0211/checkone.sh
You can put this command inside a shell script myrenamescript.sh file like so:
#!/bin/bash
mv /system/0211/syscheck.sh /system/0211/checkone.sh
Now set the script as executable
chmod a+x myrenamescript.sh
Now you can run it:
./myrenamescript.sh

Related

i have a part of code that works in git bash but not when i make a script out of it

Hello awesome community i am using git bash to run this command: cp -r thisfolder thatfolder to copy the contents of a folder in another one
now i want to make a script out of this to create a scheduler to run that script and my script looks like this
#!/bin/bash
set -euo pipefail
IFS=$'\n\t
cp -r thisfolder thatfolder && echo done > debug.txt
#the debug.txt is just to know if the script copied stuff
its a .bat script and all folders and script are on the same directory but for some reason it doesnt copy the files as git bash does
any thoughts??

How to pass a directory path containing spaces to the -C option of tar in a bash script?

i'm building up in a bash script a tar command like this:
/usr/bin/tar -cvjf /tmp/archive.tar.bz2 -X excl.txt -C '/cygdrive/c/Users/Utente/dir with spaces/' dir1 dir2 dir2
/usr/bin/tar: '/cygdrive/c/Users/Utente/dir: Cannot open: No such file or directory
if i test the command in the shell it works fine.
if i run the script the script complains. i think that something fails when tar tries to change directory.
of course i can change directory in the script an then avoid the use of the -C option but i miss the opportunity to use the -X option.

How to make a bash script for mac?

I'm trying to make this bash script but get this: Error reading *.docx. The file doesn’t exist
Here's the script:
#!/bin/bash
textutil -convert txt *.docx
cat *.txt | wc -w
I'm currently running it from the folder but I'd like to make it a global script I can just call from any current folder.
If you want to make it available on your whole system you need to move it to a bin location like so
chmod a+rx yourscript.sh && sudo mv yourscript.sh /usr/local/bin/yourscript
then you can use it like a normal script in any folder

mv: cannot move file to '': No such file or directory in bash

I have following command
mv 15827.png "$(<15827.png.txt)"
Which is moving the file 18827.png to the path specified in 15827.png.txt, and it is working fine.
But when I moved this command to shell script
#!/bin/bash
mv 15827.png "$(<15827.png.txt)"
I'm running it with:
sh myscript.sh
Its not working and I am getting following error:
mv: cannot move '15827.png' to '': No such file or directory
The file 15827.png.txt contains the digit 7 and there is folder named 7 in the current directory.
The problem is that you're running the script with sh, but it needs to be run with bash, because $(<filename) is a bash extension.
Make the script executable:
chmod 755 myscript.sh
and then run it with:
./myscript.sh
This will execute the script using the shell named in the #! line.

create a shell script with a shell script (mac)

I've been creating mac shell executables with this method:
Create a file;
Add #!/bin/sh;
Add the script;
Run chmod 755 nameofscript.
I now need to create a shell script to create a shell script in another directory and make it executable (with chmod) so that it can be run on startup.
#!/bin/sh
dir=/tmp
fnam=someshellscript
echo '#!/bin/sh' > $dir/$fnam
echo 'find /bin -name "*X*"' >> $dir/$fnam
chmod 755 $dir/$fnam
#!/bin/sh
echo "script goes here!" > /path/to/place
chmod 755 /path/to/place
?

Resources