why does ./ not work as a directory? [Linux] - linux

I'm trying to install NET. 6.3 on my chromebook with Linux but when I try to execute
./dotnet-install.sh -c Current
in the Linux Terminal it always gives me this error:
-bash: ./dotnet-install.sh: No such file or directory
Any way around it/any fix for it?
I have done sudo -i so I got full permission and I have put the file I'm trying to execute in a lot of folders including my Linux folder.
Any help is appreciated!

I suppose you should:
chmod +x ./dotnet-install.sh
./dotnet-install.sh -c Current
or
/bin/bash dotnet-install.sh -c Current

There are two ways to execute a script on a UNIX/Linux platform:
Either you make the script executable, as explained in the other answer.
Either you use the sh or other relevant command for launching it, I prefer this way of working.
So, I would propose you to launch the following command:
sh ./dotnet-install.sh -c Current

Have you tried the pwd command to see on which path are you working on?
Then try to ls | grep dotnet-install in the current directory, if there isn't output you have to change directory.
Probably you are trying to execute the dotnet-install.sh in a wrong directory, i suppose.
Another way is to get file trough wget command on terminal to be sure you download the file in the correct directory.
Regards

Related

lzma command not found when executing shell script only under sudo

I am building project source code in a SUSE server.
The project build.sh called "lzma" command to compress kernel.
The project build.sh need "sudo" to get access to some system command.
But I has tried to execute "sudo ./build.sh", and the shell always report error: "lzma: command not found."
I could execute "lzma" in shell with my user account. It works fine.
I also write a test shell script named "test.sh" which calls "lzma" command.
I found that it fails with same error message if I excute "test.sh" with "sudo" .
But if I execute "test.sh" without "sudo", it works fine.
Why ?
"Command not found" within sudo is almost invariably the result of an environment variable such as PATH, LD_LIBRARY_PATH (if what's missing is not the executable but a shared library it requires) or the like being altered.
You can pass working values through your environment variables through explicitly:
sudo PATH="$PATH" ./test.sh
Sudo uses a different Path then your user account.
EDIT (see comments)
Try and execute:
type lzma
Say the output reads something like '/usr/bin/lzma', then just copy that output into your sudo command like (for example):
sudo /usr/bin/lzma
That should do the trick. You should also write the full path of lzma into your shell script if you are to run it as root.
EDIT 2:
Or, as Charles Duffy mentioned in his answer, you could leave all things as is and simply use PATH="$PATH" in your command if you are trying to execute your file as SUDO or as a different user.

"cannot execute binary file" when trying to run a shell script on linux

I am very new to linux and shell scriprting.
I am trying to run a shellscript from secure shell (ssh) on linux using following commands:
chmod +x path/to/mynewshell.sh
sh path/to/mynewshell.sh
I get this error:
path/to/mynewshell.sh: path/to/mynewshell.sh: cannot execute binary file.
Tried using this command:
bash path/to/mynewshell.sh
I get the same error.
Tried with this command: su - myusername sh path/to/mynewshell.sh
It is asking for my password and giving me this error: no such file or directory.
1.The result of cat -v path/to/mynewshell.sh is:
^#^#^#^#^#^#^#^#Rscript "$dir"/diver_script.R
done
2.When tried 'less path/to/mynewshell.sh' i got this on my terminal:
#!/bin/bash/Rscript^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#
^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#^#
for dir in /path/to/* ; do
^#^#^#^#^#^#^#^#Rscript "$dir"/myRscript.R
done
3.When i ran file path/to/mynewshell.sh : i got this "Bourne-Again shell script text executable"
Please give any advice on how I can try executing the shellscript.
chmod -x removes execution permission from a file. Do this:
chmod +x path/to/mynewshell.sh
And run it with
/path/to/mynewshell.sh
As the error report says, you script is not actually a script, it's a binary file.
I was getting the same error running my shell script through a bash interpreter in PowerShell. I ran dos2unix myscript.sh on the shell script, and now it runs ok.
From a proposed duplicate:
run_me.sh.xz: run_me.sh.xz: cannot execute binary file
This is because the file is compressed, as indicated by the .xz extension. You need to remove the compression before the file can be used.
xz -d ./run_me.sh.xz
chmod +x ./run_me.sh # probably not necessary if you already did that before
./run_me.sh
Other compression schemes like gzip (.gz extension), bzip2 (.bz2 extension) etc behave similarly; you just have to know the name of the command to uncompress it, which is of course usually easy to google.
To anyone else having the problem i had.
i was trying to run a 16 bit unicode text file converted to a shell script, this doesn't work as all 16 bit unicode text files have a 0xFFFE marker at the start making mac os not like the file and this gives the “cannot execute binary file” error.
open the text file click on "Format" at the top, go down to "Make Plain Text" click it.
open your terminal type chmod 777 /path/to/file.sh
put in terminal: /path/to/file.sh to run it
That script is simply not a shell script.
A shell script is usually readable and contains shell code.
The output your cat command shows looks indeed like it's a binary of some sort.
As some note, it might be because of a file conversion issue when copying but it looks more like an actual binary to me.
You can check what it is identified as with the file command so:
file path/to/mynewshell.sh
Just start with a clean script and rewrite the code, it looks like you just want to run some R scripts in a directory?
Make sure the R scripts point to the right R script executioner.
In my case I had a bash script that would not execute. The file was originally generated from a find ... -print0 command. Leaving a \0 character the script, removing that character solved my problem.

-bash: ./setantenv.sh: Permission denied

I am trying to install hybris software on my mac os system and my system have the prerequisites like 64 bit os, 4 mb…ram…..etc. To run ant command I need to set up a ant environment first. There is a file called setantenv.sh file in my platform folder. In mac terminal I am in platform folder and typing ./setantenv and pressing enter. I am getting the following error. I tried different commands like chmod +x setantenv.sh or chmod 755 platform, BUT I could not succeed. After the successful environment setup only I can run my ant clean all command
-bash: ./setantenv.sh: Permission denied
Please help me with each steps to solve this issue. thanks
First off, you might just be able to fix it by setting the executable bit:
chmod a+x setantenv.sh
But I am also not sure if you are doing the correct call. You need to source the setantenv.sh file, so you need to do:
. ./setantenv.sh
(the leading "." is the source command and then you point to the file that you are sourcing)
So effectively, the setantenv.sh file doesn't really need the executable bit.
The errors you get happen because you have an older version of ant in your current system, the setantenv.sh will point your terminal to the correct one (that is shipped with each hybris version and resides in $HYBRIS_HOME/bin/platform)
So once you do it right, that error should disappear.
Note that you need to do this . ./setantenv.sh every time you open a new terminal.
Hope that helps!
There are 3 steps to getting this to work.
Navigate to hybris/bin/platform
1) Execute the command 'chmod 777 setantenv.sh'
2) In the terminal, type 'bash' and press enter. This will take you to bash prompt.
3) Type '. ./setantenv.sh'.
These 3 steps will work.
Cheers
I fix it by removing the if condition at the beginning.
Replace your setantenv.sh with below bash code.
PLATFORM_HOME=`pwd`
export PLATFORM_HOME
export ANT_OPTS="-Xmx512m -Dfile.encoding=UTF-8"
export ANT_HOME=$PLATFORM_HOME/apache-ant-1.9.1
chmod +x "$ANT_HOME/bin/ant"
chmod +x "$PLATFORM_HOME/license.sh"
export PATH=$ANT_HOME/bin:$PATH
$ > chmod a+x setantenv.sh
$ > . ./setantenv.sh

Bash script not running

I am trying to learn bash scripting and I'm using Ubuntu Linux. I have written a simple Bash file to count the number of files in current directory. I have written the following script in a file:
#! /bin/bash
ls -1 | wc -l
And saved the file with the name countFile.
But when I am trying to execute the script using ./countFile it is not executing. It shows the following error:
bash: ./countFile: Permission denied
The countFile is in my home directory so why I haven't the permission. Am I doing something wrong or missing some important thing? Moreover, the ls -1 | wc -l command gives me the correct output when I run it from the terminal.
So how can I run the countFile script?
While you are giving like this,
./countfile
You have to make that file as executable using chmod.
chmod +x countfile
Or else you can use the other interpreter like this.
sh countfile
while executing the file we need a execute permission for that file,
we can change the permission or
we just run as
. countfile
hew . will represent the current working shell

cp command won't run if executed from shell script

i have very simple shell script
#!/bin/bash
cp -rf /var/www/ksite/app2/* /var/www/ksite/app
echo "----"
echo "done"
but seems cp command fails
if i execute
cp -rf /var/www/ksite/app2/* /var/www/ksite/app
from terminal everything work ok. Can someone tell me how to include cp in shell script?
Thanks
We seem to have doubt as to how this script fails. If there is no error message then this is a strange one. I suggest:
On the command line (which works), do a which cp
Whatever the reply, then copy that and use it as the cp in the script (e.g. /bin/cp)
Check the widcard expansion, run your script with bash -x script-name and see if you get what you expect.
echo $? after the copy in the script - if it is zero then it (thinks it) worked.
Do a ls -ld /var/www/ksite/app from your script, maybe someone set a symbolic link?
If it still fails, source the script from the command-line and see if that works . script-name
Double check that the copy did actually fail! (maybe that should be step 1.)
Make sure you really have bash at /bin/bash. I think a batter hash bang is:
#!/usr/bin/env bash
This uses the env command to locate the bash binary and set the environment.
I had similar problem. What helped me:
I used windows and putty to write script, so I had \r\n at the end of lines. Be sure, you have only \n symbol.
I copied files and the only way it worked for me at script was cp <source_dir>/fileName <dest_dir>/fileName whereas at command line cp <source_dir>/fileName <dest_dir> worked well too.
Just covering all the bases .. do the permissions vary between the excutions .. i.e. do you execute one with sudo/root privileges, the other as user (unlikely, but thought I'd ask since we don't know what the exact error is)
Similar issue to Vladmir where the script was created in Windows. I created a new file "my_bash_script.sh" in the linux environment using VIM, then read the contents of my script into the file:
:r file_made_in_windows.sh
Then I saved, closed, then set the file as executable:
chmod 744 my_bash_script.sh
From there, I ran the script:
./my_bash_script.sh
...and it worked. What a weird issue. I was confounded for a moment.

Resources