Text Replacement in Terminal

Hi,

I was wondering if there is a way to substitute some text inside a command in the terminal. I don't think that to save an alias solves the problem because I think it is only for entire commands.


For example, I'd like to save "Music/GarageBand" as "gb" and then be able to write in terminal "cd gb/Project1" to directly go to the directory Music/GarageBand/Project1.


Thanks

MacBook Pro 16″, macOS 12.3

Posted on Apr 25, 2022 12:23 AM

Reply
Question marked as Top-ranking reply

Posted on Apr 25, 2022 4:04 AM

In your shell initialization script, you can define


gb=$HOME/Music/GarageBand


Then use


cd $gb/project1


An alternative approach is to create a symbolic link


cd $HOME

ln -s Music/GarageBand gb


Then when in your home folder, you can use


cd gb/project1


NOTE: with a symbolic link, gb is going to look like a file to the ‘ls’ command, and an Alias to the Finder.

1 reply
Question marked as Top-ranking reply

Apr 25, 2022 4:04 AM in response to davideselvatici

In your shell initialization script, you can define


gb=$HOME/Music/GarageBand


Then use


cd $gb/project1


An alternative approach is to create a symbolic link


cd $HOME

ln -s Music/GarageBand gb


Then when in your home folder, you can use


cd gb/project1


NOTE: with a symbolic link, gb is going to look like a file to the ‘ls’ command, and an Alias to the Finder.

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.

Text Replacement in Terminal

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