Comments (6)
If you handle the flag like this, you'll have to figure out how to get the nickname only without the flag preceding it when you try to grep within $current
.
For example, if you wrote addalias -s lp="commands"
you want to grep for alias lp=
to see if it exists, not alias -s lp=
.
(It's handleable with regex, but you just have to handle it.)
from myaliases.
@GiselleSerate, I might be wrong about this, but I think you can just use $1
to get lp="commands"
. You won't have to parse the entire command, and hence, you won't have to deal with the -s
only sometimes existing.
from myaliases.
That was my first thought, but I think it breaks over spaces, or that was my problem when trying to use numerical arguments even without trying to handle the option.
from myaliases.
Unless you're doing that because you want to preserve quotes.
Actually, have you ever tried using single quotes instead of double? Ex: alias lp='commands'
? I think that might solve the quotes problem.
from myaliases.
Except that requires the user to type it in that way, and I'm pretty sure the normal alias command lets you use double
from myaliases.
So I tried to do some experiments with quoting. Take a look at this:
This question and this question seem to explain why this happens. To summarize, when a command is executed, bash first evaluates the line that the user typed according to its normal rules. Part of this evaluation includes removing quotes from the parameters, and in the case of double quotes, bash also does some sort of evaluation of the content of the string inside the double quotes such that variables are converted to their actual values (as seen above). In the case of single quotes, the content of the string inside the quotes is interpreted literally.
So it seems clear that single quotes perform differently than double quotes. But what does this have to do with us, as writers of functions that take parameters that may be double or single quoted?
Well, I think it explains that quoting of parameters is a tool of the user, and not something that we should ever handle or deal with. If the user chooses to use single quotes, it's because they want our function to get the literal string that they typed. Likewise, if the user chooses to use double quotes, it's because they want our function to get an evaluated version of their string.
From this stack overflow answer, it seems that this is indeed what happens with the original alias command. I think this also shows that most of the time the user will likely want to use single quotes, not double quotes, when calling alias
.
So if your alias command was to use "$1"
, I don't think it would ever have to deal with spaces. I'm still not sure why you were seeing numerical arguments break over spaces, but it could have been that $1
wasn't surrounded by double quotes in your function?
from myaliases.
Related Issues (20)
- options HOT 6
- Reran install script and .included gave me this HOT 2
- cds - too many file descriptors? HOT 3
- wiki better m8 HOT 1
- cds tab complete shell conditional agh HOT 2
- add guidance about setup/install to wiki
- document git and hg and grep
- prepending .included line into .bash_aliases HOT 7
- comments in cds command
- unalias for altalias? HOT 1
- double slashes in cds tab completion HOT 3
- alias in alias command
- test suite HOT 3
- Setup script's jank on an RPI HOT 6
- Setup script should finish off by sourcing HOT 1
- Somehow enforce make
- some ideas
- cds - is not portable
- wsl open cmd overrides default open cmd HOT 2
- WSL 2 alternative to SFTP Net Drive using SSHFS HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from myaliases.