Hi, I'm trying to create a script that will display the contents of the users directories, but i'm confused about how to incorporate the shift properly.
The problem I'm getting with my script is that it goes throught the first couple of directories but then returns an error as it loses the first directory when continuing the search to other directories (I hope that makes sense?!)
EDIT: I apologise, that was the old problem, now the problem is the path to be searched adds the wrong directories so it looks in paths that do not exist
Here's my code, any help would be greatly appreciated.
EDIT2: I have also tried suppressing the error returned by the ls to dev null by editing the line inside the function:
and also
but niether work, both return the same output, in other words they are still not suppressesing the standard error.
I'm not quite sure what ls ~username would do, when I try it, it outputs the same as a normal ls command...
Basically what I want my script to do is display a visual representation of the specified directory and all its sub directories (like the tree command).
I have managed to supress the original ls error by adding the 2>/dev/null to the function call itself which seems to work ok now:
But my script still does not work correctly, it will scan through the first directory found and display it along with all the subdirectories, but when it comes to loop back to the original directory and display the next directory it won't scan through and display the subdirectories of it. (I'm finding it quite hard to explain but I hope you can understand)
the output given will be something like: (where the . and number represent the directories and subdirectories)
direc1
direc1.1
direc1.1.1
direc1.1.2
direc1.2
direc1.2.1
direc2
and then it halts, where as i want it to display an output like:
direc1
direc1.1
direc1.1.1
direc1.1.2
direc1.2
direc1.2.1
direc2
direc2.1
direc2.1.1
direc2.2
direc2.2.1
direc3
direc3.1
direc3.1.1
direc3.2
direc4
...etc
I still cannot understand: given your example direc1.1, 1 is the name of the subdirectory or some sort of auto incremented id?
Do you want to produce an output similar to this one:
I still cannot understand: given your example direc1.1, 1 is the name of the subdirectory or some sort of auto incremented id?
Do you want to produce an output similar to this one:
Kind of... Simply put, what I would like to do is create a script which displays an output similar to the unix tree command
but only list directories and subdirectories, no files.
I hope that is clearer. And I greatly appreciate your help and time.
to better explain my direc1, direc1.1 blah blah...
direc1 would be the parent directory, direc1.1 and direc 1.2 would be sub directories of direc1, and direc1.1.1 would be a sub directory of the subdirectory direc1.1
Hello Gurus :)
I'm "currently" (for the last ~2weeks) writing a script to build ffmpeg with some features from scratch.
This said, there are quite a few features, libs, to be downloaded, compiled and installed, so figured, writing functions for some default tasks might help.
Specialy since... (3 Replies)
Hello,
I am reading one of the AIX manuals about shell scripting and (AIX 5) and I found this example when introducing to functions:
function usage
{
prog="$1"; shift
print -u2 "$prog: usage: $prog $@"
exit 1
}
This example is meant to be easy but I don't understand what it is... (5 Replies)
hey guys, im trying to learn bourne shell atm and I'm having some issues with functions.
so heres my code:
#!/bin/bash
##functions
memory () {
free -m
}
space () {
df -h
}
ip () { (5 Replies)
Hi,
Here is my code as below:
test.ksh:
=======
#!/bin/ksh
option="${1}"
while
do
case $1 in
-f) FILE="${2}"
echo "File name is $FILE"
;;
-d) DIR="${2}"
echo "Dir name is $DIR"
;;
-*)
echo "`basename ${0}`:usage: | " (5 Replies)
Sorry for my english
Hello all my friends and seniors, i had created a programm in c++
(anagrammig of word) it works fine but i cannot understand how exactly
recursion is working , i mean oh.. first look at the code .
#include <iostream>
#include <string>
... (1 Reply)
Hi Guys,,
I tried to create a recursive function in unix.
The following is the code.
#/bin/sh
function(){
n=$1;
if ; then
out=1;
echo "inside if for 0";
else
out = `$n * function "$n-1"`;
echo "inside if for $n-1;
fi (3 Replies)
I want to halt a tail recursive function after certain validation. I want to come out of entire recursion without unwinding phase. How can i achieve that . The coding is done in C language. (5 Replies)
Hello every body. I am trying to find the factorial using the following code. But it is giving the syntax error. I tried very much but in vain. Thanks in advance for helping me
factorial()
{
if
then
y=`expr $1 - 1`
x=$(( $1 \* factorial $y ))... (6 Replies)
Hello !
I need some help with my simple bash script.
This script removes all files ( with name given in $1 ) in current dir and subdirectories .
The problem is with first loop in the script ( for file in * ; do ) .
When I run the sript in my home directory this script display sometimes( ... (5 Replies)
I'm using the UNIX csh and i wish to use recursion to nav my way up (or down as it is) a given folder.
My little test script is called "r" and takes a folder as argv (or $1)
#!/bin/tcsh -f
set allFiles = `ls -A $argv`
cd $argv
while ($#allFiles)
if (-d... (1 Reply)