"Export" command no longer working in zshrc?

Hello all. Recently upgraded my old iMac to a new(-er-ish) MBP and when migrating my old .bash_profile file found it no longer worked because Apple switched from Bash to ZSH. By simply renaming bash_profile to zshrc I got some commands to work but not the "export x='y' " commands. I forget what exactly these are called but they sure made things simpler on my older system. Is there a way to update these commands for ZSH?


MacBook Pro (2021)

Posted on Apr 29, 2023 5:56 PM

Reply
Question marked as Top-ranking reply

Posted on Apr 30, 2023 12:06 PM

Is the zshrc or .zshrc?


if there is no leading period, zsh is not going to read it.


also if you change any of the zsh initialization files, you should quit the terminal emulator and start a new session.


Re: -wrap could be a command, as it is a valid file name. Totally against convention, but the execvp() call would not care as long as it was an executable file found in PATH.


Heck, ‘[‘ is a command. In the original PDP-11 based UNIX implementation, ‘[‘ was hard linked to the /bin/test command. So


if [ $# -lt 2 ]; then


is the same as


if test $# -lt 2; then

9 replies
Question marked as Top-ranking reply

Apr 30, 2023 12:06 PM in response to B.Griffin

Is the zshrc or .zshrc?


if there is no leading period, zsh is not going to read it.


also if you change any of the zsh initialization files, you should quit the terminal emulator and start a new session.


Re: -wrap could be a command, as it is a valid file name. Totally against convention, but the execvp() call would not care as long as it was an executable file found in PATH.


Heck, ‘[‘ is a command. In the original PDP-11 based UNIX implementation, ‘[‘ was hard linked to the /bin/test command. So


if [ $# -lt 2 ]; then


is the same as


if test $# -lt 2; then

Apr 30, 2023 5:21 PM in response to B.Griffin

B.Griffin wrote:

The dash command is unique to the program I feed with this Export command.

Maybe try a sanity check and try it with some normal command.

PS: I just tried the same sequence as an alias. Nope.

Randall has a good point. The export command isn't even for commands at all. It's for environment variables. It "exports" a variable out of the current context. The alias command is for commands.

Apr 30, 2023 9:54 AM in response to etresoft

As an example I have the following command in the zshrc file:


export m='-warp '


When I use this in terminal as:


$m 2


It does not work on my new m1 mac, but does on my old intel mac.


But if I simply type in terminal:


-warp 2


It does.


What is going wrong?


I have used one of the simplest export commands I have in zshrc here but many are much longer and Export really helps not having to repetitively type so much to get simple things done.

Apr 30, 2023 3:06 PM in response to B.Griffin

The dash command is unique to the program I feed with this Export command.


It is .zshrc


Every time I modify the .zshrc file I restart terminal. Terminal executes other commands in the .zshrc file just fine, but not Export (" export x=' y ' ") commands. This is the one thing it doesn't seem to like now since switching systems.


Randall_2023: IIRC this process didn't work with aliases in the past, but I could try again. IIRC this was because there had to be a variable ("y" in the above example) entered in the command line not found in the alias/export command. Basically a version of "load file in directory x/y/z"/file-name with "/file-name" something you enter in the command line after the export command. The export command just simplifies the first, much longer and invariant, part. Aliases are good (again, IIRC, its been a while since I've messed around with this) if you have the full "x= a b c" sequence you just want a shortcut to, not if "a b c" is different every time and you're only shorting the "x=" part of the command.


PS: I just tried the same sequence as an alias. Nope.

Apr 30, 2023 3:13 PM in response to B.Griffin

You could create a function that works just fine inside the .bash_profile. I'd guess it's do-able for zshrc as well. Here is an example of one I created for changing mouse speed. It uses a replaceable parameter and even gives a warning if one isn't entered. See if you can tweak it for your needs. Good Luck.


function mspeed ()

    {

        if [ -z "$1" ]; then

    # Display usage if no parameters given

                echo "NOTE: You need to add a mouse speed value of 1-8. Default setting was originally set to 3";

                echo "Correct Usage should be: mspeed [1-8]. After changing, you must log out and back in.";

        else

                defaults write .GlobalPreferences com.apple.mouse.scaling "$1";


        fi


}

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

"Export" command no longer working in zshrc?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.