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?
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
If I need to change to some directory several levels up, I usually do this in bash:
cd ../../../../some/other/folder
Since it is quite annoying to type all those periods and slashes, I was wondering if there is some shorter way to type it; like for example:
cd ..4/some/other/folder
I have not been able to find it so far from for example cd --help.
There's no standard way.
You can declare a function that takes a number of parent directories as the first argument, and the relative path as the second one:
cdu () {
local n=$1
local p=""
while ((n--)) ; do
p+=../
done
cd "$p/$2"
}
You can then shorten cd ../../../bin to cdu 3 bin
What I use is
alias ..='cd ..'
alias ...='cd ../..'
To get 6 levels up, I just type ... + Enter three times.
according to cd man page, the immediate answer is "no".
if it helps, you may add the following to your .bashrc:
export prev1=".."
export prev2="../.."
export prev3="../../.."
export prev4="../../../.."
and so on.
example:
export prev4="../../../.."
mkdir -p /1/2/3/4/5
cd /1/2/3/4/5
pwd => result is /1/2/3/4/5
cd $prev4
pwd => result is /1
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 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 &
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
When I hit tab in zsh it will show me a list of possible completions:
$ ls<tab>
src/ bin/ res/ docs/
Then when I execute the command, the output from that command replaces what was once the list of options:
$ ls src/
script1.py script2.py
$
When I do the same in fish, it does not replace the list, but puts a new prompt line under the list, similar to the way it works in bash:
$ ls<tab>
src/ bin/ res/ docs/
$ ls src/
script1.py script2.py
$
Can I get the list replacement feature that zsh has in fish?
It's not possible yet, but it's planned! It's tracked in http://github.com/fish-shell/fish-shell/issues/291
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