Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi,
I hope someone here can help.
I'm trying to write a script/alias that creates a text file called whatever I input(in a particular set location in Documents -for example).
I know I can just use "touch filename.txt" but I'm looking for something more challenging to learn from as I can't find suitable examples where an argument is used as the input.
Everything I find is Hello world, Echo this etc.
For example the Alias is called blankfile
When I type> blankfile newfile(or whatever I want). It creates this named file in Documents.
yes, an alias cannot do this.
it would be better to write a short script, make it executable, and place it in $HOME/bin (assuming that's in your PATH).
or a function, can do the same.
makefile()
{
file="/home/userx/Documents"
cd $file
touch $1
cd
}
because touch creates the file in the current working directory. Then just type in the function name and file name then it does what it is told to do.
You said script so that's where my mind went to the first time.
Remember to open up a new terminal each time you make changes to your .bashrc to update the terminal for testing your changes.
All you need to do is figure out how to get it back to where you where at, if you where not in your parent home dir working in the terminal, that is simple enough, yes? .
Perfect! I think this is the closest to what I'm looking for. Although I found an alternative script method(with help above from Awesome Machine and your previous input).
At least I've learnt something from your assistance(and everyone) and now aware of a few ways to accomplish the task.
****************************
My main goal is to write a multi-function script(with some kind of menu-maybe Dialogue) which can handle basic admin tasks on a remote linux pc.(add printer- [several] and copy driver over), check for and delete lock files with Firefox etc etc, maybe backup bookmarks file etc etc.
I know how to do these tasks on an individual basis but stringing them in to a menu is going to be some challenge.(in another post - if I need it ?!?).
Perfect! I think this is the closest to what I'm looking for. Although I found an alternative script method(with help above from Awesome Machine and your previous input).
At least I've learnt something from your assistance(and everyone) and now aware of a few ways to accomplish the task.
****************************
My main goal is to write a multi-function script(with some kind of menu-maybe Dialogue) which can handle basic admin tasks on a remote linux pc.(add printer- [several] and copy driver over), check for and delete lock files with Firefox etc etc, maybe backup bookmarks file etc etc.
I know how to do these tasks on an individual basis but stringing them in to a menu is going to be some challenge.(in another post - if I need it ?!?).
my pleasure, do not forget to click
Did you find this post helpful? Yes <-- the yes if you found it helpful.
I think it might also help to add that arguments are separated by whitespace, and are numbered $1, $2, $3, etc. So, in
Code:
$ command argument1 argument2 argument3
$1=argument1, $2=argument2, and $3=argument3. And you can have more arguments.
wouldn't using the $1 $2 $3 assignment to a different value mess up the information being gotten off of the command line?
Code:
#!/bin/bash
#argument numbers
echo $1
echo $2
echo $3
echo
#number of arguments passed to a shell script
echo $#
#
echo;echo
# the arguments given in sequence
echo $@
maybe you just wrote it back words ( backwards ).
Code:
$1=argument1, $2=argument2, and $3=argument3
argument1=$1
argument2=$2
argument3=$3
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.