Skip to main content
The 2024 Developer Survey results are live! See the results
deleted 11 characters in body
Source Link

First of all, aliases are not functions and do not accept arguments. Rather, aliases are simple substitutions: When you type goto foo on the command line and press Enter, the shell simply replaces goto with the value of the alias, before executing the command line.

Therefore, $@ does not expand to the arguments passed to your alias. In fact, in this case, it expands to the arguments passed to shell or the script you're sourcing. This is why goto works correctly the second time: You have now passed a directory as an argument when sourcing your .zshrc file and $@ will expand to that argument when you declare the alias again.

Additionally, since you're using "double quotes", $@ expands immediately when you declare the alias. JustTo see that this is the case, right after your shell has started up, type alias without arguments to view your aliases right after your shell has started up and you'll see that this is the case.

If you want goto to be able to handle arguments, you should declare it as a function: goto() { cd $@ && ... }

However, as a rule, ⚠️you should not source ~/.zshrc. Depending on what's in your dotfiles, this can lead to all sorts of problems.

Instead, if you've made changes to your .zshrc file and you want to apply them, you should either restart your terminal (by closing the current tab/window and opening a new one) or restart the shell (by typing exec $SHELL).

First of all, aliases are not functions and do not accept arguments. Rather, aliases are simple substitutions: When you type goto foo on the command line and press Enter, the shell simply replaces goto with the value of the alias, before executing the command line.

Therefore, $@ does not expand to the arguments passed to your alias. In fact, in this case, it expands to the arguments passed to shell or the script you're sourcing. This is why goto works correctly the second time: You have now passed a directory as an argument when sourcing your .zshrc file and $@ will expand to that argument when you declare the alias again.

Additionally, since you're using "double quotes", $@ expands immediately when you declare the alias. Just type alias without arguments to view your aliases right after your shell has started up and you'll see that this is the case.

If you want goto to be able to handle arguments, you should declare it as a function: goto() { cd $@ && ... }

However, as a rule, ⚠️you should not source ~/.zshrc. Depending on what's in your dotfiles, this can lead to all sorts of problems.

Instead, if you've made changes to your .zshrc file and you want to apply them, you should either restart your terminal (by closing the current tab/window and opening a new one) or restart the shell (by typing exec $SHELL).

First of all, aliases are not functions and do not accept arguments. Rather, aliases are simple substitutions: When you type goto foo on the command line and press Enter, the shell simply replaces goto with the value of the alias, before executing the command line.

Therefore, $@ does not expand to the arguments passed to your alias. In fact, in this case, it expands to the arguments passed to shell or the script you're sourcing. This is why goto works correctly the second time: You have now passed a directory as an argument when sourcing your .zshrc file and $@ will expand to that argument when you declare the alias again.

Additionally, since you're using "double quotes", $@ expands immediately when you declare the alias. To see that this is the case, right after your shell has started up, type alias without arguments to view your aliases.

If you want goto to be able to handle arguments, you should declare it as a function: goto() { cd $@ && ... }

However, as a rule, ⚠️you should not source ~/.zshrc. Depending on what's in your dotfiles, this can lead to all sorts of problems.

Instead, if you've made changes to your .zshrc file and you want to apply them, you should either restart your terminal (by closing the current tab/window and opening a new one) or restart the shell (by typing exec $SHELL).

Link to https://unix.stackexchange.com/a/532591/413610
Source Link

First of all, aliases are not functions and do not accept arguments. Rather, aliases are simple substitutions: When you type goto foo on the command line and press Enter, the shell simply replaces goto with the value of the alias, before executing the command line.

Therefore, $@ does not expand to the arguments passed to your alias. In fact, in this case, it expands to the arguments passed to shell or the script you're sourcing. This is why goto works correctly the second time: You have now passed a directory as an argument when sourcing your .zshrc file and $@ will expand to that argument when you declare the alias again.

Additionally, since you're using "double quotes", $@ expands immediately when you declare the alias. Just type alias without arguments to view your aliases right after your shell has started up and you'll see that this is the case.

If you want goto to be able to handle arguments, you should declare it as a function: goto() { cd $@ && ... }

However, as a rule, ⚠️you should not source ~/.zshrc.you should not source ~/.zshrc. Depending on what's in your dotfiles, this can lead to all sorts of problems.

Instead, if you've made changes to your .zshrc file and you want to apply them, you should either restart your terminal (by closing the current tab/window and opening a new one) or restart the shell (by typing exec $SHELL).

First of all, aliases are not functions and do not accept arguments. Rather, aliases are simple substitutions: When you type goto foo on the command line and press Enter, the shell simply replaces goto with the value of the alias, before executing the command line.

Therefore, $@ does not expand to the arguments passed to your alias. In fact, in this case, it expands to the arguments passed to shell or the script you're sourcing. This is why goto works correctly the second time: You have now passed a directory as an argument when sourcing your .zshrc file and $@ will expand to that argument when you declare the alias again.

Additionally, since you're using "double quotes", $@ expands immediately when you declare the alias. Just type alias without arguments to view your aliases right after your shell has started up and you'll see that this is the case.

If you want goto to be able to handle arguments, you should declare it as a function: goto() { cd $@ && ... }

However, as a rule, ⚠️you should not source ~/.zshrc. Depending on what's in your dotfiles, this can lead to all sorts of problems.

Instead, if you've made changes to your .zshrc file and you want to apply them, you should either restart your terminal (by closing the current tab/window and opening a new one) or restart the shell (by typing exec $SHELL).

First of all, aliases are not functions and do not accept arguments. Rather, aliases are simple substitutions: When you type goto foo on the command line and press Enter, the shell simply replaces goto with the value of the alias, before executing the command line.

Therefore, $@ does not expand to the arguments passed to your alias. In fact, in this case, it expands to the arguments passed to shell or the script you're sourcing. This is why goto works correctly the second time: You have now passed a directory as an argument when sourcing your .zshrc file and $@ will expand to that argument when you declare the alias again.

Additionally, since you're using "double quotes", $@ expands immediately when you declare the alias. Just type alias without arguments to view your aliases right after your shell has started up and you'll see that this is the case.

If you want goto to be able to handle arguments, you should declare it as a function: goto() { cd $@ && ... }

However, as a rule, ⚠️you should not source ~/.zshrc. Depending on what's in your dotfiles, this can lead to all sorts of problems.

Instead, if you've made changes to your .zshrc file and you want to apply them, you should either restart your terminal (by closing the current tab/window and opening a new one) or restart the shell (by typing exec $SHELL).

added 216 characters in body
Source Link

First of all, aliases are not functions and do not accept arguments. Rather, aliases are simple substitutions: When you type goto foo on the command line and press Enter, the shell simply replaces goto with the value of the alias, before executing the command line.

Therefore, $@ does not expand to the arguments passed to your alias. In fact, in this case, it expands to the arguments passed to shell or the script you're sourcing,. This is why goto works correctly the second time: You have now passed a directory as an argument when sourcing your .zshrc file and $@ will expand to that argument when you declare the alias again.

Additionally, since you're using "double quotes", it$@ expands immediately when you declare the alias. Just type alias without arguments to view your aliases right after your shell has started up and you'll see that this is the case.

If you want goto to be able to handle arguments, you should declare it as a function: goto() { cd $@ && ... }

However, as a rule, ⚠️you should not source ~/.zshrc. Depending on what's in your dotfiles, this can lead to all sorts of problems.

Instead, if you've made changes to your .zshrc file and you want to apply them, you should either restart your terminal (by closing the current tab/window and opening a new one) or restart the shell (by typing exec $SHELL).

First of all, aliases are not functions and do not accept arguments. Rather, aliases are simple substitutions: When you type goto foo on the command line and press Enter, the shell simply replaces goto with the value of the alias, before executing the command line.

Therefore, $@ does not expand to the arguments passed to your alias. In fact, in this case, it expands to the arguments passed to shell, and since you're using "double quotes", it expands immediately when you declare the alias. Just type alias without arguments to view your aliases and you'll see that this is the case.

If you want goto to be able to handle arguments, you should declare it as a function: goto() { cd $@ && ... }

However, as a rule, ⚠️you should not source ~/.zshrc. Depending on what's in your dotfiles, this can lead to all sorts of problems.

Instead, if you've made changes to your .zshrc file and you want to apply them, you should either restart your terminal (by closing the current tab/window and opening a new one) or restart the shell (by typing exec $SHELL).

First of all, aliases are not functions and do not accept arguments. Rather, aliases are simple substitutions: When you type goto foo on the command line and press Enter, the shell simply replaces goto with the value of the alias, before executing the command line.

Therefore, $@ does not expand to the arguments passed to your alias. In fact, in this case, it expands to the arguments passed to shell or the script you're sourcing. This is why goto works correctly the second time: You have now passed a directory as an argument when sourcing your .zshrc file and $@ will expand to that argument when you declare the alias again.

Additionally, since you're using "double quotes", $@ expands immediately when you declare the alias. Just type alias without arguments to view your aliases right after your shell has started up and you'll see that this is the case.

If you want goto to be able to handle arguments, you should declare it as a function: goto() { cd $@ && ... }

However, as a rule, ⚠️you should not source ~/.zshrc. Depending on what's in your dotfiles, this can lead to all sorts of problems.

Instead, if you've made changes to your .zshrc file and you want to apply them, you should either restart your terminal (by closing the current tab/window and opening a new one) or restart the shell (by typing exec $SHELL).

Source Link
Loading