Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: unshift




On 2024-04-01 06:54, Mark J. Reed wrote:
I haven't read your whole message yet, but to unshift a new value in front of the positional params, all you have to do is this:


    set -- "$new" "$@"

And now $1 is "$new", $2 is whatever $1 used to be, and so on.

... ah, I see, you want to just undo a shift. Well, AFAIK you can't do that without manually saving the value that was in $1 before the shift somewhere. Then you can use set to put it back.

No problemo.  saving the previous '$1' is no issue, I can hardly expect it to be saved somewhere automatically, that would be a courtesy hardly of much use and not worth the bother.  The 'set' trick above is exactly perfect. 

Thanks Mark.


Messages sorted by: Reverse Date, Date, Thread, Author