guide.bash.academy | Bash Academy - The Bash Guide | Script Programming library
kandi X-RAY | guide.bash.academy Summary
kandi X-RAY | guide.bash.academy Summary
Bash Academy - The Bash Guide
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of guide.bash.academy
guide.bash.academy Key Features
guide.bash.academy Examples and Code Snippets
Community Discussions
Trending Discussions on guide.bash.academy
QUESTION
I have a bash program that uses parameter expansion to go back one level from the directory I'm on. For example, if I'm in the directory /path/to/my/dir
, my program will allow me to go to /path/to/my/
without retyping the whole path or using cd -
a bunch of times.
Recently, I decided to start using the fish shell and I love it. But I'm not really sure how to do parameter expansion in the fish shell.
I've tried to create an alias to my bash program in ~/.config/fish/config.fish
so that back
will run bash /path/to/back.sh
, but this doesn't run the program in the current environment. Changing it to . /path/to/back.sh
doesn't really help since fish doesn't know how to run a bash script.
I was wondering if there is a parameter expansion feature in fish? I tried reading the documentation and couldn't find it.
Any help would be appreciated.
Thanks.
...ANSWER
Answered 2019-Jun-09 at 03:28Your back.sh script can't possibly work unless you are running it via .
or source
. That's because a child process cannot affect the environment, which includes the CWD, of any other process. If you run back.sh 1
it will only change the CWD of that script which isn't meaningful since the script immediately exits.
Fish does support parameter expansion but not brace constructs like ${prev_dir%/*}
. Fish prefers using commands for such manipulations rather than complex syntax. So, for example, to strip everything after the last slash you would do something like this in fish:
QUESTION
I looked at a bash guide where I found this example: http://guide.bash.academy/expansions/
...
ANSWER
Answered 2017-Jul-08 at 16:52This is a common gotcha with wildcards. The question to ask yourself is, is there any way to split up myscript.txt
such that the first piece matches !(my)
and the second matches *.txt
?
The answer is, counter-intuitively, yes: If you "split" "myscript.txt"
into ""
(the empty string) and "myscript.txt"
then the empty string matches !(my)
and "myscript.txt"
matches *.txt
. The empty string is a valid match!
QUESTION
for example
...ANSWER
Answered 2017-Apr-25 at 03:24Because a=100
is not a command, and you can't evaluate assignments like that.
In order to properly evaluate the assignment try:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install guide.bash.academy
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page