Help for basics of shell
I'm super newb and want to start learning by doing simple stuff. So maybe you could give me some support on those tasks -
Creating a procedure that would take file's name as an argument checking current folder AND IF there is no such file (under the name of argument just taken) it would print the message and create a file under mentioned name. I bet completing this task would "get me on the track" and I could continue from there on my own for a while. THANKS! |
Read the manual page on test and touch. Will take at most 5 minutes. What you are asking is the simplest of things.
|
Quote:
|
Same 'test' command with '-d' switch does.
Code:
for d in *; do test -d "$d" && echo $d; done |
Quote:
Code:
for d in /home/paulius/Desktop/ Code:
/home/paulius/Desktop/ The $d is variable, right? |
Quote:
'&&' is Binary AND operator. If previuous command succeeds then it executes the rest. 'd' is a variable and we reference it's value using '$d'. |
Quote:
When I tried to use $1 instead of /home/paulius/Desktop/* and then executed it Code:
bash sh.sh /home/* Quote:
|
Member response
Hi,
Welcome to LQ! Quote:
Quote:
Have fun & enjoy! :hattip: |
I want to make a script that creates files in selected directory.
list is the list of names input by user when executing shell file Code:
bash shell.sh file01 file02 file03 Code:
list=($1 $2 $3 $4) EDIT: Also, reading the variables from file "list.txt" would be even better. How could I do that? EDIT2: Code:
#!/bin/bash/ |
Quote:
And in second code: 'touch /home/paulius/Desktop/shell/shell_testas $line' change to: 'touch /home/paulius/Desktop/shell/shell_testas/$line' |
Quote:
That way the OP learns the reasons why. Quote:
Code:
ARRAY=(( $1 $2 $3 $4 )) **Also note you should not be using "for" loops idly: http://mywiki.wooledge.org/DontReadLinesWithFor ***As a matter of fact do read http://mywiki.wooledge.org/BashGuide and http://mywiki.wooledge.org/BashFAQ as it will help you tremendously. Quote:
Code:
#!/bin/bash With the "for" loop gone you can start using variables to store values, "getopts" to parse input and perform error handling where its most efficient: Code:
#!/bin/bash |
All times are GMT -5. The time now is 10:20 PM. |