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.
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).
I found myself doing this all the time:
open terminal
cd /mydir/folder
parse deploy
Is it possible to create some kind of file I can click on, that does this automatically?
Thanks
create file run.sh and run - chmod +x run.sh
The file should look like this -
#!/bin/bash
cd /mydir/folder
parse deploy
I have a shell script which calls for different executables from it.
The shell script and the executables are within same directory and I am trying to run it from there. Still, on running, I get the error, "executable" not found- No file/directory exists.
What should I do???
First, You need to provide permission to the File :
chmod +x filename
Then, execute the binary file by,
./filename
The current directory is typically not in your command path, for security reasons. You need to provide the path explicitly, that is
./mycommand
instead of
mycommand
(Keep in mind, though, that this will break if you run the script from a different directly. ./mycommand is relative to the directory you run from, not the directory where the script is stored.)
I wrote a shell script where I copy my .bashrc file as well as custom dotfiles to a backup folder and then replace them in my home folder with another .bashrc file which will then source my custom dotfiles.
However, after the script does its job, if I try to execute the aliases I included in the new files I get the error No command found. Only after I source the .bashrc file manually in the terminal I have access to them.
From what I understand, the script I'm running is executing in a sub-shell (?) which will terminate on execution.
How can I run the script and have new commands/aliases/functions available without having to source the .bashrc file myself or restarting the terminal?
Well, it appears that instead of running my script via sh script.sh, I can source it like source script.sh, which will behave exactly as I wanted.
Solution
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.