Hey guys, i'm having trouble complete one of my bash scripts
I'm hoping to ---
Modify bash so that then the user types "ls" the command that is executed is "ls -al"
Modify the point of entry in bash when the user accesses it, moving the initial location to /var
I've somewhat done #2, but I can only do it to myself. I'm trying to create a script that creates a new user and than modifies the point of entry. But for some reason I cannot access the file. If I just make a script that does
echo "cd /var" >> /home/eric/.bashrc
Then it will work.. however if i'm not doing it to my own account it will not work
And i'm totally lost on #1, what commands change commands? And what files store the commands?
Here is my partial code:
#!/bin/bash
#adds a user
echo "What is the name of the new user? "
read newUser
#creates the new user
sudo useradd -m -s /bin/bash $newUser
#modifies point of entry in bash
echo "cd /var/" >> /home/$newUser/.bashrc
echo "Entry of bash has been changed to /var/"
#code of modify the 'ls' command to 'ls -al'
#code
I'd really appreciate some help. Thank you guys!
-eric
Thank you for your responses guys! I appreciate them all!
However, I still cannot find a way to append things to a different file to the new user I created for the .bashrc file.
After I create a new user I'd like to edit the new users .bashrc file but I cannot find a way to edit that file.
sudo sh -c "echo alias ls='ls -al >> /home/$newUser/.bashrc
Does not work
I mean, all of this will work perfectly if I was editing my own currently logged in user .bashrc file
But what about after I create a user?
In theory the script would
create a $newUser of your choise
create an alias in the .bashrc for the $newUser
modify the point of entry in bash in the .bashrc file for the $newUser
Again; it would work perfectly if the user used the script for himself. But that is not the way i'm hoping to do it.
So far this is my full script but it will only work for myself not for the $newUser
#!/bin/bash
#Adds new user
echo "What is the name of the new user?"
read newUser
#creates a user
sudo useradd -m -s /bin/bash $newUser
#modifies point of entry in bash
echo "cd /var/" >> /home/$newUser/.bashrc
echo "Entry of bash has been changed to /var/"
#adds an alias
echo "alias ls='ls -al' " >> /home/$newUser/.bashrc