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'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)
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)
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)
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)
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)
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,
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)
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)
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)
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)