change "startx" command | edit: and "ls" [SOLVED]

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
lvleow
Level 2
Level 2
Posts: 52
Joined: Sat Nov 06, 2010 5:32 pm

change "startx" command | edit: and "ls" [SOLVED]

Post by lvleow »

I know this is a little ODD of a request, but how do you go about changing the startx command? For example, instead of startx, I want to type startxx to get into the GUI.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 5 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
xenopeek
Level 25
Level 25
Posts: 29597
Joined: Wed Jul 06, 2011 3:58 am

Re: change startx command

Post by xenopeek »

Easy:

Code: Select all

alias startxx="/usr/bin/startx"
Just type that on the terminal to have it work immediately. If you want it to work after reboot, add that line to your ~/.bashrc file.

If you don't want startx to work anymore, that is something different...
Image
lvleow
Level 2
Level 2
Posts: 52
Joined: Sat Nov 06, 2010 5:32 pm

Re: change startx command

Post by lvleow »

not quite what I was looking for, but it pointed me in the right dir. thank you. :) renaming startx in /usr/bin to startxx worked more permanently (alias only works for current session?).
User avatar
xenopeek
Level 25
Level 25
Posts: 29597
Joined: Wed Jul 06, 2011 3:58 am

Re: change startx command

Post by xenopeek »

lvleow wrote:not quite what I was looking for, but it pointed me in the right dir. thank you. :) renaming startx in /usr/bin to startxx worked more permanently (alias only works for current session?).
Well, I didn't want to suggest that as it may break things (i.e., anything that needs to run startx now can't). Like I wrote, edit your ~/.bashrc to make the alias work after reboot.
Image
lvleow
Level 2
Level 2
Posts: 52
Joined: Sat Nov 06, 2010 5:32 pm

Re: change "startx" command | edit: and "ls"

Post by lvleow »

If I edit the bashrc and still put in startx, it'll work right? I don't want that. I want to script a custom error when the input is startx. Besides, what applications might use startx? If you're in the GUI, there's no need for it. And if you're in command, what kind of program wants to interrupt what it's doing and start the GUI? I'm kind of curious, cause I'd prefer not to get that error while doing something in either, so I can just avoid those kinds of apps?

Also, is there a way to rename "ls" to lets say "lss"? Also having ls playback a custom script error? Are there any applications that might use this command as well?

I know, I'm weird. hahaha :lol:
User avatar
xenopeek
Level 25
Level 25
Posts: 29597
Joined: Wed Jul 06, 2011 3:58 am

Re: change "startx" command | edit: and "ls"

Post by xenopeek »

lvleow wrote:If I edit the bashrc and still put in startx, it'll work right? I don't want that. I want to script a custom error when the input is startx. Besides, what applications might use startx? If you're in the GUI, there's no need for it. And if you're in command, what kind of program wants to interrupt what it's doing and start the GUI? I'm kind of curious, cause I'd prefer not to get that error while doing something in either, so I can just avoid those kinds of apps?

Also, is there a way to rename "ls" to lets say "lss"? Also having ls playback a custom script error? Are there any applications that might use this command as well?

I know, I'm weird. hahaha :lol:
I suggest you read up on the Bash alias command.

Basically you could do in your ~/.bashrc:

Code: Select all

alias startxx="/usr/bin/startx"
alias startx="echo do not use startx"
alias lss="/bin/ls"
alias ls="echo do not use ls"
As long as you alias your alternative command to the full path of the command's binary, you can then create and alias for the original command to something else (like a warning in this case). If people then type "startx" or "ls" they get a warning, but "startxx" and "lss" work as expected.

If you want this to apply system-wide, for all users on the machine, you have to add the lines to the /etc/bash.bashrc file. The ~/.bashrc is only for your user.
Image
lvleow
Level 2
Level 2
Posts: 52
Joined: Sat Nov 06, 2010 5:32 pm

Re: change "startx" command | edit: and "ls"

Post by lvleow »

thank you, I appreciate your help. :)
Locked

Return to “Scripts & Bash”