after building the project with a gnumake, I looked on the internet and executed
sudo chmod +x filename
afterwards, I cannot execute the file and gets the error
-bash : ./filename cannot execute binary file
I compiled it on the same device as the one that I am executing it in.
Related
I have project structure like this
project
|app
|script
inside script folder, there are files such as 'run'
run file content:
#!/bin/bash
npm start
I want to run the file 'run' while I'm at the root of my project by typing only command 'run'. How would you do this?
This is sh file. In order to execute sh file on linux this file has to be executable.
Make sure this file has X permission.
If there is no x permission on file simply execute the command
chmod +x run.sh
Then execute the file by typing
./run.sh
For windows you need to create .bat file.
I'm not quite sure what you want but assuming you need a way to execute a file from node.js, you can use child_process module and child_process.exec method to start any executable.
Assuming the run file in the script directory is executable (if not, run chmod +x script/run), it can be executed by running ./script/run.
If you want to avoid having to type the name of the directory (script), you could append the script directory to your PATH environment variable. If you’re running a POSIX compatible shell (not csh or tcsh), this can be done using:
export PATH="$PATH:/path/to/project/script"
This will allow you to run any executable command in the script directory without having to specify the name of the directory, e.g., run.
NB: be sure that there aren’t common command names in the script directory as these commands can be run from any directory (including outside the project directory) after it has been added to the PATH. That’s also why I suggest adding it to the end of the PATH (so it’s the last directory that’s searched for executable commands).
When I create .sh file, I need to give permission for him to be executed, there is a file that can be configured or command applied so I can already create the file with permission of execution?
Through Terminal, type in this command:
chmod +x file.sh
To execute the command, do:
./file.sh
If you want an application, you can make an Automator using the previous commands.
I'm trying to learn to write shell scripts and use the Terminal.
In Users/user/Development/linux I've got a script called sysinfo_page.
So I'm in the linux folder in the terminal and I can see the sysinfo_page when I type the ls command.
However, when I enter the following command:
sysinfo_page > sysinfo_page.html
I receive the following message:
-bash: sysinfo_page: command not found
How do I resolve this?
If you want to run a script file form the current directory, you have to write ./ before your script name:
./script.sh
Your command may not be an executable file. Try this:
chmod +x sysinfo_page
./sysinfo_page > sysinfo_page.html
The first line will set the eXecutable flag on the file, the second will run it from the current dir. Note that if you want to run a file in the current directory and that dir is not included in your PATH, you need to prepend ./ or else the shell won't find it.
When i login to the cygwin terminal and type:
cd "cygdrive/c/existing/path"
it tells me, "no such file or directory". i am sure the path exists... do i miss a special cygwin package, or do i have a false configuration? i am puzzled...
It behaves the same when i try to call the cygwin bash from a windows batch file.
what i basically want to do is creating a windows batch file which starts cygwin and executes a shell script with a specified working directory as its described in this blog post: http://blog.dotsmart.net/2011/01/27/executing-cygwin-bash-scripts-on-windows/
my batch file seems to work, it does the following command:
%_CYGBIN%\bash.exe --login "cd %_CYGPATH%" "./%_CYGSCRIPT%"
but cygwin won't execute the 'cd' command. The console output of my batch file is:
/usr/bin/bash: cd /cygdrive/c/existing/path: No such file or directory
cd '/cygdrive/c/existing/path'
# ^
# \
# --- need forward slash (/) before the "c"
I just made a .c file and compiled it with gcc in the terminal on OS X 10.8.2.
My syntax was gcc -o <filename> <sourcefile> and that was fine. Now I see I have an executable and file <filename> tells me as such, but I'm not sure how to actually run it beside double clicking the icon, /lame. When I try running the executable by just typing I get command not found, but I thought it was executable...?
Thank you.
EDIT: I"m so stupid, it was just open <filename>
Unix will only run commands if they are available on the system path, as you can view by the $PATH variable
echo $PATH
Executables located in directories that are not on the path cannot be run unless you specify their full location. So in your case, assuming the executable is in the current directory you are working with, then you can execute it as such
./my-exec
Where my-exec is the name of your program.
To run an executable in mac
1). Move to the path of the file:
cd/PATH_OF_THE_FILE
2). Run the following command to set the file's executable bit using the chmod command:
chmod +x ./NAME_OF_THE_FILE
3). Run the following command to execute the file:
./NAME_OF_THE_FILE
Once you have run these commands, going ahead you just have to run command 3, while in the files path.