Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I am working on a Mac. I am trying to use the fork command to run another sh file on Terminal.app:
$ fork sh
bash: fork: command not found
What's wrong with my command?
fork isn't a shell function.
You can run an executable script directly /path/to/script.
You can source/. a script to run it in the current shell . path/to/script.
You can also run the shell directly on the script bash /path/to/script.
To run a command in the background, you can put an ampersand (&) on the end.
So for example, if your command is /path/to/some/program some args here, you could run it in the background (and continue entering commands in your foreground shell) using:
/path/to/some/program some args here &
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 3 years ago.
Improve this question
Suppose I have the following code in a StackOverflow response:
$ export FLASK_APP=main.py
$ export FLASK_DEBUG=1
$ python -m flask run
Is there an easy way to copy and paste this without the $ signs, so I can directly paste this into my terminal?
You could do:
. <( sed 's/^\$ //' <<'PASTE'
**paste here**
PASTE
)
Or, make that into a function:
undollar() { . <( sed 's/^\$ //' ); }
Than you use that like
$ undollar<hit enter>
<paste here>
<hit Ctrl+D>
Both of these approaches use the . command, so effects are seen in the current shell: for example with the commands you list, the FLASK_APP and FLASK_DEBUG environment variables remain in the shell.
As noted by Charles Duffy, old versions of bash cannot source a process substitution: see Why source command doesn't work with process substitution in bash 3.2?
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I have a shell script written like so:
#!/bin/bash
cd Documents/Hi_tech_team_10/
chmod +x /Users/twoodwa/Documents/Hi_tech_team_10/test.rb
ruby test.rb
when i execute it in the terminal it works perfectly, but when i set it as a cron job by doing
crontab -e
then editing and saving the file with
*/10 * * * * /Users/twoodwa/Documents/Hi_tech_team_10/test.sh
the script either doesn't execute, or it is doing something different than just running it like it does from the terminal.
what is the issue?
EDIT: i have changed the script to use absolute paths as so, still not working :
#!/bin/bash
chmod +x /Users/twoodwa/Documents/Hi_tech_team_10/test.rb
ruby /Users/twoodwa/Documents/Hi_tech_team_10/test.rb
First checkpoint: if script is executable
Second checkpoint: you should use absolute paths
Third checkpoint: never trust environment. Cron has it's own environment (true, suggested in comments)
Good idea: Addding some logging to a terminal/file to check execution and when it had failed.
The issue is in crontab, change crontab to pointing to test.rb
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I am trying to ssh into my amazon server. I have two ways of doing it, one works and one doesn't, and I'm not sure why the second one does not work.
First way:
ssh -i path-to-pem-file username#public-ip
This works.
Second way:
ssh -i "path-to-pem-file" username#public-ip
This results in "Warning: Identity file "path-to-pem-file" not accessible".
Both of the above commands are run from the terminal on Mac OSX. Why do the double quotes break the statement? thanks.
If your using shell expansion or other special characters their special meanings will not be interpreted when quoted. They are considered literal values.
You can replicate this with the ~ or special character for $HOME
Doesnt work
ssh -i "~/mypemkey.pem" ec2-user#somehost
Works
ssh -i ~/mypemkey.pem ec2-user#somehost
Essentially the ssh application is trying to find a literal file path ~/ instead of /Users/someuser/ when expanded.
Want to see it in action under the hood.... test it!
Create a simple bash script
echo "echo \$1" > test.sh
Execute it
/bin/bash test.sh ~/Desktop
outputs: /Users/phpisuber01/Desktop
/bin/bash test.sh "~/Desktop"
outputs: ~/Desktop
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 8 years ago.
Improve this question
I'm trying to run a script in my Terminal on OSX. I run it like this:
$ script.sh input.txt output.txt
-bash: Script.bash: command not found
This script has worked before (with no changes to it) and it appears in the working directory when using the ls command. I don't know if this means anything but previously my script files had a .s logo on their filetype picture and now it is blank, like a .txt file (in Finder). Any help would be much appreciated! I tried using script.bash and the same thing happens. Thanks!
try "./COMMAND HERE"
or ". COMMAND HERE"
you need to have an explicit path if the script isn't in your $PATH
./script.sh input.txt output.txt
also you will want to make sure that the script is set as being executable
like:
chmod 777 script.sh
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I wont write some script in Ruby on Linux server. I need statistic from server and I'm a beginner in Ruby.
I have problem with Linux commands, because if I use exec to use Linux command, my program is fallen without error.
disks = ["sda", "sdb"]
Code:
disks.each do |disk|
puts "disk test start"
exec "smartctl -a /dev/#{disk} > /tmp/sestavy/#{disk}"
puts "disk test end"
end
Output:
[root#banan sestavy]# ruby test.rb
disk test start
[root#banan sestavy]#
Thanks
Honza
That's just what exec does: it replaces the currently running program with a new one. This is not specific to Ruby, it works the same way in the shell, in C, in pretty much any other environment.
When you use exec, it replaces the current process with what you want to execute. So it won't return to your Ruby script. See this explanation for different methods for shell execution.