Unable to run tar command - invalid option -- '▒' - bash

I've run into a problem while running a tar script. I am getting an invalid option, as shown in the screenshots, that is stopping the script running. I don't get why however as the command worked outwith the script. Can anyone help me?
The script:
The error:

Thanks to Paul R I have an answer. No idea how to mark his comment as the answer though so here it is:
Some older versions of tar don't like the - at the start of the
commands - try tar cvpfz .... – Paul R 5 mins ago

Are you copy and pasting the command, instead of hand-typing it in terminal?
In my case, I was getting:
tar: invalid option -- '�'
I was pasting into terminal, the command from a raw text file, which I had copied from a tutorial:
tar –xvzf bitcoin-0.20.0-x86_64-linux-gnu.tar.gz
I hand-typed the entire command:
tar -xvzf bitcoin-0.20.0-x86_64-linux-gnu.tar.gz
and it worked. I suspect it was something like an extra space character or a - or similar which was not working.

In my case, i tried chmod 777 'FILE_NAME' for unlock the file.
Then installing, it works well!

Related

bash no abash: /src/github.com/tomnomnom/gf/gf-completion.bash: No such file or directory

When ever I do sudo su in ubuntu i get this weird error everytime there is not any problem in using anything but I just want to ask why is it coming even tho even do i have deleted this file already why is it automatically executing bash to this file
The problem was an old code in his ~/.bashrc file which was found by grep -Fre gf-completion.bash /etc/ ~/.bashrc*:
/root/.bashrc:source $GOPATH/src/github.com/tomnomnom/gf/gf-completion.bash

Stanford CS231n: how to download the dataset (using .sh file in windows)?

I am self-learning the convelutional neural network from the stanford cs231n course. I am trying to finish the assignment1. However, I just got totally confused about how to download the data. I followed the instructor and see
Download data: Once you have the starter code, you will need to
download the CIFAR-10 dataset. Run the following from the assignment1
directory:
cd cs231n/datasets
./get_datasets.sh
I don't understand what does it mean by "run" the following. Run what exactly? Previously, I use R so I understand what does "run R" means. But here it does not say run "what" or run the code in "where".
So I tried to run the code in command prompt, Anaconda Prompt, PowerShell or even Git Bash. The command prompt game error of "." is not recognized as an internal or external command. The PowerShell does not give error but does not give any result either. It just open a Text Document of code
# Get CIFAR10
wget http://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz
tar -xzvf cifar-10-python.tar.gz
rm cifar-10-python.tar.gz
The Git Bash gives me error of
get_datasets.sh: line 2: wget: command not found
tar (child): cifar-10-python.tar.gz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
rm: cannot remove 'cifar-10-python.tar.gz': No such file or directory
How to download this data? Please help! Thanks.
Download wget
& copy wget.exe to your git
C:\Program Files\Git\mingw64
then restart the git bash or Navigate to your folder where get_datasets.sh file is present.
run the following command in git bash
sh get_datasets.sh
Navigate to your folder where get_datasets.sh file is present using cmd.
Use the command .\get_datasets.sh in command prompt.
Make sure you are not missing wget. If wget is missing, install wget on your local machine and then run the shell script.
After installing wget properly use the instruction mentioned at the start.

Make shell script change script location

I have currently put together a script to move files from one directory to another.
This has gone ok however I was wondering if there was a way via a shell script to get it to run from anywhere on the server e.g I give the script for someone to use on their server and they can put the script anywhere and it will run.
I know a workaround is to put the script in /usr/local/bin or usr/bin and you can run it from anywhere but that is not what I want.
Is there a way that my script will auto run from usr/local/bin regardless of if it is in /scripts for instance?
Please see my script below:
#!/bin/sh -x
mkdir -p /var/Alitest
echo "This is a test that I have created. This is to
see if the output is successful I normally do this manually but a script is required" > /var/Alitest/action.txt
sed -i 's/This is a test that I have created/The test has been successful/g' /var/Alitest/action.txt
chmod 744 /var/Alitest/action.txt
chown root:root Alitest/action.txt
mv /var/Alitest/action.txt /script/action.txt
Any help would be greatly appreciated :)
Also in my log output for the script the following error is shown:
sed: 1: "/var/Alitest/action.txt": invalid command code A
Any ideas?
You can make a soft link in /usr/local/bin for your script. Then it will be in everyone's path to be executed.
e.g. ln -s /script/yourscript.sh /usr/local/bin/yourscript.sh
After reviewing the matter further I have decided the the best way to action this is to add the folder destination e.g /scripts to my path.
This can be done by vimming into the .bashrc file on the server and adding the below line:
export PATH=/dir_name:$PATH
remember to refresh the profile in order for the changes to take effect.
You can check if this has been successful by running the below command:
echo $PATH
There is no way to get your script to do this however this would be better then a softlink as if you add it to $PATH then you do not have to go through the task of adding softlinks each time.
Thank you all for your help.
Kind Regards
Ali

Batch script calls a Bash script but output file does not populate

I have a batch script that looks like this
# echo off
c:/cygwin/bin/bash -li each_sec_extract.bash c:/iperfprocess/sprint/file1.txt > c:/iperfprocess/sprintbashed/file1.txt each_sec_extract.bash c:/iperfprocess/sprint/file2.txt > c:/iperfprocess/sprintbashed/file2.txt
When i run this as is, the CYGWIN bash terminal pops up and I can observe the script producing the output I want on the screen, however, when I go to the directory where the file should be located (c:/iperfprocess/sprintbashed/), I am greeted by an empty text file. When i enter instructions from the CMD line manually, I receive the same result. However, when I run the instruction directly from CYGWIN, it works flawlessly. The part that frustrates me the most, this script used to work fine, then I started getting SED: permission denied errors which forced me to run bash.exe in administrative mode.
Any ideas about what might be happening or what a solution may be? Thank you in advance for any and all help provided.
Is this any different?
#echo off
c:/cygwin/bin/bash -li each_sec_extract.bash c:/iperfprocess/sprint/file1.txt > c:/iperfprocess/sprintbashed/file1.txt
c:/cygwin/bin/bash -li each_sec_extract.bash c:/iperfprocess/sprint/file2.txt > c:/iperfprocess/sprintbashed/file2.txt
The SED: Permission error was the underlying cause of the empty output files that was experienced. Running bash in administrative privileges was only a work around that didn't fix the actual problem. For some reason, sed.exe became corrupt. The solution was comprised of downloading UnxUtils from http://sourceforge.net/projects/unxutils/?source=dlp and replacing the sed.exe found from CYGWIN/bin/ and replacing it with the one in the UnxUtils zip file.
I ran my script after these steps and everything worked perfectly as it did prior to the issue.

Remove package identifier file during installation

I'm a newbie in OSx development.
I'm creating an installer package using Packagemaker 3.0.4. Since I want to remove the local settings of my app during installation, I decided to remove the com.identifier.plist. However, I'm not that good in scripting and I'm just starting to explore what Packagemaker is capable of.
Ideally, I want my implementation to be as simple as this:
Check if the .plist file exists
Remove it.
I have tried:
#!/bin/sh
defaults delete ~/Library/Preferences/com.identifier.AppName.plist
Then I saved the delete.sh file to the Desktop. I opened the Packagemaker app and provided the path to my Desktop: /Users/MyName/Desktop/delete.sh in the Scripts Postflight. Then I executed build & run. It didn't work. I thought that it might probably be the script, so I changed it to:
#!/bin/sh
rm ~/Library/Preferences/com.identifier.AppName.plist;
Then I loaded the delete.sh file the same way as I did on the script above. But I received this error:
Mar 29 20:50:54 Mac-mini installd[5425]: PackageKit: Install Failed: PKG: post-flight scripts for "com.testIdentifier.test.AppName.pkg"\nError Domain=PKInstallErrorDomain Code=112 UserInfo=0x100404220 "An error occurred while running scripts from the package “test.pkg”." {\n NSFilePath = "./postflight";\n NSLocalizedDescription = "An error occurred while running scripts from the package \U201ctest.pkg\U201d.";\n NSURL = "./Contents/Packages/test.pkg -- file://localhost/Users/MyName/Desktop/AppName.mpkg/";\n PKInstallPackageIdentifier = "com.testIdentifier.test.AppName.pkg";\n}
If anyone who has a Step-by-Step implementation of creating & adding script to the Packagemaker, and perhaps, my scripts aren't correct, it would be awesome if you could help me out.
Thank you so much in advance! :)
Did you try to launch your delete.sh from terminal? Looks like you have an error in syntax - ';' at the end of the rm command, and you should use -f flag for the rm command (see man rm) in other case script will prompt for confirmation and postflight script can't be interactive.
Edit: as 一二三 mentioned semicolon - is not the point, you should probably look to his answer. And before you'll create your package just try your script in terminal (you can do sudo su before to login as root)
I've got it...
Here's my script:
#!/usr/bin/env bash
file=~/Library/Preferences//com.identifier.AppName.plist
if [ -e "$file" ]
then
# file is found
/usr/bin/defaults delete ~/Library/Preferences//com.identifier.AppName
else
# file not found."
fi
exit 0
I then added it to PackageMaker. I'm not really sure if I'm right but I might have just forgotten to add the script's file into the contents. That's why it never worked earlier. I just put the script's path on the postflight.
Anyway, thanks a lot to everyone for the tips.

Resources