Why do double quotes break the ssh statement? [closed] - macos

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

Related

What is the "[" binary file in my "/bin" folder for? (MacOS Big Sur M1 chip) [closed]

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 2 years ago.
Improve this question
I am newbie in Operation System, and trying to catch up by exploring my new computer.
This morning, I was just exploring the bin file, and I saw a weird folder called "[". What is this?
I did not create or install anything in the "/bin" folder yet. So it was not created by me. What is the "[" binary file in my "/bin" folder for?
[ is the test program. As the man page suggests, it's used like
[ condition ]
and evaluates to either a zero (for true) or a non-zero value (for false). In the case of zsh on macOS, the man page says that false is represented by 1. Note that the whitespace after the square bracket is important since that whitespace indicates to the shell that you want to run the [ program.
Despite the presence of the program, that executable is probably not used often. It appears that you're using zsh, which is the default shell on macOS. In zsh, [ is a built-in which takes precedence over /bin/[. This can be verified by
% which -a [
[: shell built-in command
/bin/[
The man page for the built-in can be found by man zshbuiltins.
If you want to explicitly use the program in /bin, then your command should look like
/bin/[ condition ]
Example
Supposed you're running a shell script where you want to check a condition. For example, you want to check whether a file exists. [ is frequently used for this purpose. Here is an example
if [ -f myFile.txt ]; then
date > myFile.txt
else
echo "File was created on $(cat myFile.txt)."
fi

How do I copy and paste Bash without dollar signs? [closed]

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?

why is my cron job not executing properly? [closed]

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

Command not found: fork [closed]

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 &

Can't run shell scripts [closed]

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

Resources