![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| question about testing in shell programming | thungmail | Shell Programming and Scripting | 6 | 04-09-2008 02:04 PM |
| question about testing in shell programming(modifications were made) | thungmail | Shell Programming and Scripting | 2 | 04-08-2008 03:51 PM |
| question about testing in shell programming | thungmail | Shell Programming and Scripting | 2 | 04-08-2008 02:29 AM |
| question about testing in shell programming | thungmail | Shell Programming and Scripting | 3 | 04-02-2008 10:46 PM |
| question about about Shell programming | thungmail | Shell Programming and Scripting | 1 | 04-01-2008 01:40 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Hi i would like to write a "script" which takes a directory as an argument and the script will output the content of a file in this directory.Here is my code
Code:
#!/bin/sh #set an argument to be a specified path $1=/home/tuan/Desktop/Shell_programming/directory #check if an argument is a directory if [ ! -d $1 ] then for number in $1 do echo "$number" done<list else echo "No such that directory " fi Code:
tuan@tuan:~/Desktop/Shell_programming$ ./A3 directory ./A3: 2: directory=/home/tuan/Desktop/Shell_programming/directory: not found No such that directory tuan@tuan:~/Desktop/Shell_programming$ PS: In "directory" directory, I did created a file named "list" like below Code:
1 2 3 |
|
||||
|
Try to use something else than "$1" as the variable name... e.g.
Code:
#!/bin/sh #set an argument to be a specified path a=/home/tuan/Desktop/Shell_programming/directory #check if an argument is a directory if [ -d $a ] then for number in $a do echo "$number" done else echo "No such that directory " fi |
|
||||
|
here is the new one (with modification)
Code:
#!/bin/sh #set an argument to be a specified path a=/home/tuan/Desktop/Shell_programming/directory/list #check if an argument is a directory if [ ! -d $a ] then for number in $a do echo "$number" done else echo "No such that directory " fi Code:
tuan@tuan:~/Desktop/Shell_programming$ ./A3 /home/tuan/Desktop/Shell_programming/directory/list tuan@tuan:~/Desktop/Shell_programming$ |
|
||||
|
The way to loop over files in a directory is to list them.
Code:
for number in "$a"/*; do ... |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|