Create a script that will open a file for editing
1.If no argument is
given it will ask the user for a file name otherwise, it will open a file for
editing.
If the file already
exist it will be opened for editing.
If a file does not exist
it will open a file with the following settings
#!/bin/bash already
written on it
default permissions will be updated to –rwx------
Assuming the editor is vi, you don't need a script. Just vi filename will do as you want. Then set umask to set files creation permission as you require.
However if you really want to script this:
input_file=${1}
## Check file exists
if [ ! -f ${input_file} ]
then
## Doesnt exist - create empty file and set permission
> ${input_file}
chmod 700 ${input_file}
fi
## Edit the file
vi ${input_file}
Related
[dawidn:/mnt/c/Users/dawin]$
This is my default shell directory, all of my projects are on partition d. Is there a way to make my shell start at a certain folder by default?
Edit the file ~/.bashrc
At the end of the file add the line:
cd /mnt/d/.....
Save an close the file.
On logging back into bash, you should have the specified directory as your initial current working directory.
I am trying to do some basic scripting in linux (I am a recent transfer from windows) and I am simply trying to open a directory, create either the .odt or .odp files and then open them in their default programs.
I have tried to use "cat > filename.odt" but then i dont know how to stop the writing processes and proceed to next command.
#!/bin/bash
read -p "What would you like the file name to be: " name
cat > "$name".odt
xdg-open "$name.odt"
I want to just create the odt or odp file and then open it in either of their libre programs.
If the file is supposed to be blank when you create it you can just use: touch "$name".odt rather than cat. Also you don't need the quotes around the .odt in your last line. Your new file would look like this:
#!/bin/bash
read -p "What would you like the file name to be: " name
touch "$name".odt
xdg-open "$name".odt
Beginner linux user here,
I want to create an sh file which will open firefox, file explorer and sublime text, rather than execute these commands separately. I have created a bin folder in /home/user and have saved my .sh file there.
Everything runs as I want to except for running the sublime_text executable.
It cannot find the directory as I am running the sh file from the bin directory.
So, my question is, how can I open sublime text from another directory without creating another shell process to do so.
#!/bin/bash
cd /home/user/
./Documemnts/sublime_text_3/sublime_text
xdg-open ~/Documents/sublime_text_3/sublime_text
firefox -new-tab -url https://www.google.com
xdg-open Documents/Work/
I get No such file or directory
or
error: error opening location: No application is registered as handling this file
It looks like the directory on line 2 is misspelled:
./Documemnts/sublime_text_3/sublime_text
Notice Documemnts vs. Documents
Is it normal that all files and folders, which is made by root, is write-protected?
For instance, take a look at terminal log below:
shine#Shine-Ubuntu:~$ sudo -s
root#Shine-Ubuntu:~# echo >> 1.txt
root#Shine-Ubuntu:~# exit
exit
shine#Shine-Ubuntu:~$ rm 1.txt
rm: remove write-protected regular file '1.txt'?
(As you might know, echo >> FILE_NAME creates a file and names it FILE_NAME.)
When a file is made by root, and i want to delete it via user, it says remove write-protected regular file 'FILE_NAME'?
What should i do so the files and folders made by root won't be write-protected?
UMASK is the default permissions given when a new file or folder is created on a Linux machine. Detailed documentation/usage of umask can be seen here. Check umask setting on your system
For the life of me, I can't seem to add my Quartus bin directory to the PATH variable.
To add for all users, I edited /etc/profile by adding the line below as follows: (opening the file with sudo gedit /etc/profile)
/home/jaco/altera/14.0/quartus/bin/
I close the file, execute . ./etc/profile, after which I execute echo $PATH. This displays the directory I've just added, but when I open another shell and execute echo $PATH again, the directory is gone.
What am I doing wrong?
I have never made changes to /etc/profile but I know that env variables, aliases etc can be added to ~/.bashrc. You usually have to start a new shell or run source ~/.bashrc after editing your .bashrc file to load the new cahnges.
I think you will have to add it to all users. Also (this helps for future accounts) you can add it in your /etc/skel/.bashrc file. That is the skeleton file used when creating new users.