Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I want to write a line mac .bash_profile file while executing a shell script.I have tried below way but it gives error as
sed -i 'export PATH='$PWD:'$PATH' $HOME/.bash_profile
error
sed: 1: "/Users/dhiraj/.bash_pro ...": extra characters at the end of d command
Kindly let me know how do i resolve it ?
If you just want to append a line to your .bash_profile, what about
echo "PATH=\"$PWD:$PATH\"" >> $HOME/.bash_profile
?
And, if you want to be sure to insert only once:
grep -q -x -F 'PATH=\"$PWD:$PATH\"' $HOME/.bash_profile || echo "PATH=\"$PWD:$PATH\"" >> $HOME/.bash_profile
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
In my mac terminal I am trying to store the output of a command into a variable like this
$ animals=$(cat animals.txt | head -n $plusOne | tail -n $numberofanimals | sort -u | sed -E "s/[*#/#2]//g; s/D/d/g ; s/G/g/g ; s/E/e/g ; s/H/h/g ; s/O/o/g ; s/C/c/g ; s/[!]//gā)
>
but it does not work. When I press Enter I get a > prompt on the next line. Any idea why?
You've got a smart quote ā at the end of the line instead of a regular double quote ".
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 1 year ago.
Improve this question
Bash version 4.4.0
Ubuntu 18.04.5 LTS
Is there a way to slow down the cat command to a crawl so I can visually see the output of a file without piping the output into the more command or another file?
A bash specific approach with command substitution.
while IFS= read -rn1 -u9; do printf '%s' "${REPLY:-$'\n'}"; sleep .05 ; done 9< <(help for)
If it is a file.
while IFS= read -rn1 -u9; do printf '%s' "${REPLY:-$'\n'}"; sleep .05 ; done 9< file.txt
It looks more like reading while someone is typing.
I doubt cat itself has any parameters that can slowdown display. Script like this probably can :
#!/bin/bash
while read -r i; do echo "$i"; sleep 0.3;done< my-file.txt
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
In bash shell how do we assign extracted substring into variable without 'bad substitution' errors, please?
For example with the codes below:
fruit="apple"
echo $fruit | cut -c1-3
variable=$"{echo $fruit | cut -c1-3}"
The second line returns 'app' but the third line can't really work without bad substitution error.
Replace
variable=$"{echo $fruit | cut -c1-3}"
with
variable=$(echo $fruit | cut -c1-3)
do this instead
$ fruit=apple; var="${fruit:0:3}"; echo "$var"
app
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I'm trying to run this code in bash but I can't. Bash doesn't run it! it's like it's waiting for me to continue and it doesn't think that my command is done! But I'm already done! I know that the problem is with read <<<. so how can I fix it?
Here is my code:
for f in `ls *| head -100`; do a=$(file "$f" | grep -Po ", \K\d+x\d+"`);
> IFS="x";
> read x y <<< "$a";
> done;
>
>
You have a superfluous backtick:
for f in `ls *| head -100`; do a=$(file "$f" | grep -Po ", \K\d+x\d+"`);
# Here ---^
IFS="x";
read x y <<< "$a";
done;
ShellCheck helpfully points this out. Voting to close as a simple typographical error.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I keep getting a "command not found" error after checking a variable for the substring .txt.
Here's a simple version of my script.
myscript.sh
#!/bin/sh
if [["$1" == *.txt]]
then
echo $1
fi
Result:
> ./myscript.sh argument.txt
./myscript.sh: line 2: [[argument.txt: command not found]]
The error is because of a space needed around the brackets [[ and ]]:
#!/bin/sh
if [[ "$1" == *.txt ]]
then
echo $1
fi
That is, instead of:
if [["$1" == *.txt]]
use
if [[ "$1" == *.txt ]]