Hello,
I have a doubt:-
---------------------
Current script:-
################################################################################################
prefix=user@my-server:
find . -depth -type d -name .git -printf '%h\0' | while read -d "" path ; do (
cd "$path" || exit $?
name="`basename "$path"`"
echo <command> "$prefix$PWD.git"
) done
#################################################################################################
Output:-
<command> user@my-server:/home/git/mirror/android/adb/OpenWnn.git
<command> user@my-server:/home/git/mirror/android/adb/cts.git
<command> user@my-server:/home/git/mirror/android/adb/dalvik.git
<command> user@my-server:/home/git/mirror/android/adb/ndk.git
#################################################################################################
Desired output:-
<command> user@my-server:/android/adb/OpenWnn.git
<command> user@my-server:/mirror/android/adb/cts.git
<command> user@my-server:/android/adb/dalvik.git
<command> user@my-server:/mirror/android/adb/ndk.git
##################################################################################################
How shall i go about changing the absolute path to relative path, so that /home/git/mirror/android/adb/ndk.git
gets converted to /mirror/android/adb/ndk.git
//echo <command> "$prefix$PWD.git" ?? - anything for relative path??
##################################################################################################
Try to change the value of $PWD with the value of $name .
name="`basename "$path"`"
echo <command> "$prefix$name.git"
Hope it will solve the issue :o
Yup it was helpful
Thanks.
---------- Post updated at 06:17 PM ---------- Previous update was at 04:08 PM ----------
Hello Mann 2719,
There is an issue here:-
if i use:-
name="`basename "$path"`"
echo <command> "$prefix$name.git"
I get output as:-
<command> user@my-server:/OpenWnn.git
<command> user@my-server:/cts.git
<command> user@my-server:/dalvik.git
Which is not what i am looking for....
Basically from this code:-
prefix=user@my-server:
find . -depth -type d -name .git -printf '%h\0' | while read -d "" path ; do (
cd "$path" || exit $?
name="`basename "$path"`"
echo <command> "$prefix$PWD.git"
) done
i just don't want /home/git to be present in my output...
Desired output :-
<command> user@my-server:/android/adb/OpenWnn.git
<command> user@my-server:/mirror/android/adb/cts.git
<command> user@my-server:/android/adb/dalvik.git
<command> user@my-server:/mirror/android/adb/ndk.git
cero
May 31, 2011, 9:33am
4
So you'd like to cut off your current the directory where you start your script? Try this:
#/bin/bash
startDir=$PWD
prefix=user@my-server:
find . -depth -type d -name .git -printf '%h\0' | while read -d "" path ; do (
cd "$path" || exit $?
name="`basename "$path"`"
echo <command> "$prefix${PWD#$startDir}.git"
) done
Or else use cut command
prefix=user@my-server:
find . -depth -type d -name .git -printf '%h\0' | while read -d "" path ; do (
cd "$path" || exit $?
name="`basename "$path"`"
pwd=$(echo $PWD|cut -d'/' -f4-)
echo <command> "${prefix}${pwd}.git"
) done