Using Shell Commands to Manipulate File Paths for Use as Arguments to Another Program











up vote
1
down vote

favorite
1












I can use find like this to find a list of files:



find -type f -path "./src*" -name "*.php"`  


For example:



./src/Superuseradmin/Model/Mapper/UUID.php
./src/Superuseradmin/Model/Mapper/Mapper.php


What I need to do, is read the filename:



./src/Superuseradmin/Model/Mapper/Mapper/UUID.php  


And use it to generate PHPUnit test skeletons based on information contained in the path:



SuperuseradminModelMapperUUID  
./test/Superuseradmin/Model/Mapper/UUIDTest.php


So that I can run this command for each one:



phpunit-skelgen.phar --test -- SuperuseradminModelMapperMyMapper 
./src/Superuseradmin/Model/Mapper/MyMapper.php
./test/Superuseradmin/Model/Mapper/MyMapperTest.php









share|improve this question















migrated from serverfault.com May 31 '13 at 17:25


This question came from our site for system and network administrators.















  • Unfortunately your example is inconsistent: "For example ./src/Superuseradmin/Model/UUID.php"; "file from find command: ./src/Superuseradmin/Model/Mapper/UUID.php".
    – Hauke Laging
    May 31 '13 at 11:06










  • @HaukeLaging have fixed that
    – Gabriel Baker
    May 31 '13 at 11:10










  • It's still inconsistent. In the explanation it's UUID, in the call example MyMapper.
    – Hauke Laging
    May 31 '13 at 11:18















up vote
1
down vote

favorite
1












I can use find like this to find a list of files:



find -type f -path "./src*" -name "*.php"`  


For example:



./src/Superuseradmin/Model/Mapper/UUID.php
./src/Superuseradmin/Model/Mapper/Mapper.php


What I need to do, is read the filename:



./src/Superuseradmin/Model/Mapper/Mapper/UUID.php  


And use it to generate PHPUnit test skeletons based on information contained in the path:



SuperuseradminModelMapperUUID  
./test/Superuseradmin/Model/Mapper/UUIDTest.php


So that I can run this command for each one:



phpunit-skelgen.phar --test -- SuperuseradminModelMapperMyMapper 
./src/Superuseradmin/Model/Mapper/MyMapper.php
./test/Superuseradmin/Model/Mapper/MyMapperTest.php









share|improve this question















migrated from serverfault.com May 31 '13 at 17:25


This question came from our site for system and network administrators.















  • Unfortunately your example is inconsistent: "For example ./src/Superuseradmin/Model/UUID.php"; "file from find command: ./src/Superuseradmin/Model/Mapper/UUID.php".
    – Hauke Laging
    May 31 '13 at 11:06










  • @HaukeLaging have fixed that
    – Gabriel Baker
    May 31 '13 at 11:10










  • It's still inconsistent. In the explanation it's UUID, in the call example MyMapper.
    – Hauke Laging
    May 31 '13 at 11:18













up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






1





I can use find like this to find a list of files:



find -type f -path "./src*" -name "*.php"`  


For example:



./src/Superuseradmin/Model/Mapper/UUID.php
./src/Superuseradmin/Model/Mapper/Mapper.php


What I need to do, is read the filename:



./src/Superuseradmin/Model/Mapper/Mapper/UUID.php  


And use it to generate PHPUnit test skeletons based on information contained in the path:



SuperuseradminModelMapperUUID  
./test/Superuseradmin/Model/Mapper/UUIDTest.php


So that I can run this command for each one:



phpunit-skelgen.phar --test -- SuperuseradminModelMapperMyMapper 
./src/Superuseradmin/Model/Mapper/MyMapper.php
./test/Superuseradmin/Model/Mapper/MyMapperTest.php









share|improve this question















I can use find like this to find a list of files:



find -type f -path "./src*" -name "*.php"`  


For example:



./src/Superuseradmin/Model/Mapper/UUID.php
./src/Superuseradmin/Model/Mapper/Mapper.php


What I need to do, is read the filename:



./src/Superuseradmin/Model/Mapper/Mapper/UUID.php  


And use it to generate PHPUnit test skeletons based on information contained in the path:



SuperuseradminModelMapperUUID  
./test/Superuseradmin/Model/Mapper/UUIDTest.php


So that I can run this command for each one:



phpunit-skelgen.phar --test -- SuperuseradminModelMapperMyMapper 
./src/Superuseradmin/Model/Mapper/MyMapper.php
./test/Superuseradmin/Model/Mapper/MyMapperTest.php






bash shell-script sed find






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 at 21:37









Rui F Ribeiro

38.2k1475125




38.2k1475125










asked May 31 '13 at 10:44









Gabriel Baker

1084




1084




migrated from serverfault.com May 31 '13 at 17:25


This question came from our site for system and network administrators.






migrated from serverfault.com May 31 '13 at 17:25


This question came from our site for system and network administrators.














  • Unfortunately your example is inconsistent: "For example ./src/Superuseradmin/Model/UUID.php"; "file from find command: ./src/Superuseradmin/Model/Mapper/UUID.php".
    – Hauke Laging
    May 31 '13 at 11:06










  • @HaukeLaging have fixed that
    – Gabriel Baker
    May 31 '13 at 11:10










  • It's still inconsistent. In the explanation it's UUID, in the call example MyMapper.
    – Hauke Laging
    May 31 '13 at 11:18


















  • Unfortunately your example is inconsistent: "For example ./src/Superuseradmin/Model/UUID.php"; "file from find command: ./src/Superuseradmin/Model/Mapper/UUID.php".
    – Hauke Laging
    May 31 '13 at 11:06










  • @HaukeLaging have fixed that
    – Gabriel Baker
    May 31 '13 at 11:10










  • It's still inconsistent. In the explanation it's UUID, in the call example MyMapper.
    – Hauke Laging
    May 31 '13 at 11:18
















Unfortunately your example is inconsistent: "For example ./src/Superuseradmin/Model/UUID.php"; "file from find command: ./src/Superuseradmin/Model/Mapper/UUID.php".
– Hauke Laging
May 31 '13 at 11:06




Unfortunately your example is inconsistent: "For example ./src/Superuseradmin/Model/UUID.php"; "file from find command: ./src/Superuseradmin/Model/Mapper/UUID.php".
– Hauke Laging
May 31 '13 at 11:06












@HaukeLaging have fixed that
– Gabriel Baker
May 31 '13 at 11:10




@HaukeLaging have fixed that
– Gabriel Baker
May 31 '13 at 11:10












It's still inconsistent. In the explanation it's UUID, in the call example MyMapper.
– Hauke Laging
May 31 '13 at 11:18




It's still inconsistent. In the explanation it's UUID, in the call example MyMapper.
– Hauke Laging
May 31 '13 at 11:18










3 Answers
3






active

oldest

votes

















up vote
4
down vote



accepted










Here is a quick attempt:



for i in `find -type f -path "./src*" -name "*.php"`; do echo phpunit-skelgen.phar --test -- `echo $i | sed -e 's!./src/!!' | sed -e 's/.php//' | sed -e 's/\//\/g'` $i `echo $i | sed -e 's!./src/!./test/!' | sed -e 's/.php/Test.php/'`;done


Given the following directory structure:



./src/Superuseradmin/Model/Mapper/MyMapper.php
./src/Superuseradmin/Model/UUID.php


It should output:



phpunit-skelgen.phar --test -- SuperuseradminModelMapperMyMapper ./src/Superuseradmin/Model/Mapper/MyMapper.php ./test/Superuseradmin/Model/Mapper/MyMapperTest.php
phpunit-skelgen.phar --test -- SuperuseradminModelUUID ./src/Superuseradmin/Model/UUID.php ./test/Superuseradmin/Model/UUIDTest.php


You can then save this to a script, check it and run. Watch out for spaces in file names. They will cause trouble.






share|improve this answer





















  • Why should one ever use a pipeline of several sed instances immediately after one another instead of using one sed instance with several -e parameters? Furthermore one such line is an understanding nightmare. Compute values, assign them to variables, run commands with the variables (instead of the computing expressions).
    – Hauke Laging
    May 31 '13 at 11:28










  • Ended up using a variation of this, thanks. for i in `find -type f -path "./src*" -name "*.php"`; do mkdir -p `dirname $(echo $i | sed -e 's!./src/([[:alnum:]]*)!./test/1Test!')`; phpunit-skelgen.phar --bootstrap test/Bootstrap.php --test -- `echo $i | sed -e 's!./src/!!' -e 's/.php//' -e 's!/!\\!g'` $i `echo $i | sed -e 's/.php/Test/' -e 's!./src/([[:alnum:]]*)!1Test!' -e 's!/!\\!g'` `echo $i | sed -e 's!./src/([[:alnum:]]*)!./test/1Test!' -e 's/.php/Test.php/'`;done
    – Gabriel Baker
    May 31 '13 at 17:29




















up vote
0
down vote













You create a shell script:



#! /bin/bash

find_path="./src/Superuseradmin/Model/Mapper/UUID.php"
# find_path="$1"
class="${find_path#./src/}" # Superuseradmin/Model/Mapper/UUID.php
class="${class%.php}" # Superuseradmin/Model/Mapper/UUID
class="${class////\}" # SuperuseradminModelMapperUUID
classhead="${class%\*}" # SuperuseradminModelMapper
classtail="${class#"$classhead"}" # UUID
class="${classhead}${classtail}" # SuperuseradminModelMapperUUID
# echo "class: '${class}'"

testfile="./test${find_path#./src}"
testfile="${testfile%.php}Test.php"
# echo "testfile: '${testfile}'"

echo phpunit-skelgen.phar --test -- "$class" "$find_path" "$testfile"


And make find call this script:



find -type f -path "./src*" -name "*.php" -exec /my/script.sh {} ;





share|improve this answer




























    up vote
    -1
    down vote













    Probably you want to do something like this:



    cd src
    for i in $(find . -type f -name '*.php'); do
    SRC=$i
    DST="../test/$(dirname $i)/$(basename $i php)Test.php"
    echo "copy $SRC to $DST"
    #cp $SRC $DST
    done





    share|improve this answer





















    • for i in ...; SRC=$i instead of for SRC in...? Using a mix of two variables with the same content afterwards...?
      – Hauke Laging
      May 31 '13 at 11:30










    • I'm giving an idea to illustrate what's possible.Up to you to figure out the rest
      – Marki
      May 31 '13 at 11:36










    • You give an idea what is bad coding. Up to the others to correct that. I did that (at least point it out). This bad coding has nothing to do with "what's possible" with respect to the problem to be solved.
      – Hauke Laging
      May 31 '13 at 11:38










    • Yeah, your code is the best anyway. ;-)
      – Marki
      May 31 '13 at 12:17











    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "106"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f77809%2fusing-shell-commands-to-manipulate-file-paths-for-use-as-arguments-to-another-pr%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    4
    down vote



    accepted










    Here is a quick attempt:



    for i in `find -type f -path "./src*" -name "*.php"`; do echo phpunit-skelgen.phar --test -- `echo $i | sed -e 's!./src/!!' | sed -e 's/.php//' | sed -e 's/\//\/g'` $i `echo $i | sed -e 's!./src/!./test/!' | sed -e 's/.php/Test.php/'`;done


    Given the following directory structure:



    ./src/Superuseradmin/Model/Mapper/MyMapper.php
    ./src/Superuseradmin/Model/UUID.php


    It should output:



    phpunit-skelgen.phar --test -- SuperuseradminModelMapperMyMapper ./src/Superuseradmin/Model/Mapper/MyMapper.php ./test/Superuseradmin/Model/Mapper/MyMapperTest.php
    phpunit-skelgen.phar --test -- SuperuseradminModelUUID ./src/Superuseradmin/Model/UUID.php ./test/Superuseradmin/Model/UUIDTest.php


    You can then save this to a script, check it and run. Watch out for spaces in file names. They will cause trouble.






    share|improve this answer





















    • Why should one ever use a pipeline of several sed instances immediately after one another instead of using one sed instance with several -e parameters? Furthermore one such line is an understanding nightmare. Compute values, assign them to variables, run commands with the variables (instead of the computing expressions).
      – Hauke Laging
      May 31 '13 at 11:28










    • Ended up using a variation of this, thanks. for i in `find -type f -path "./src*" -name "*.php"`; do mkdir -p `dirname $(echo $i | sed -e 's!./src/([[:alnum:]]*)!./test/1Test!')`; phpunit-skelgen.phar --bootstrap test/Bootstrap.php --test -- `echo $i | sed -e 's!./src/!!' -e 's/.php//' -e 's!/!\\!g'` $i `echo $i | sed -e 's/.php/Test/' -e 's!./src/([[:alnum:]]*)!1Test!' -e 's!/!\\!g'` `echo $i | sed -e 's!./src/([[:alnum:]]*)!./test/1Test!' -e 's/.php/Test.php/'`;done
      – Gabriel Baker
      May 31 '13 at 17:29

















    up vote
    4
    down vote



    accepted










    Here is a quick attempt:



    for i in `find -type f -path "./src*" -name "*.php"`; do echo phpunit-skelgen.phar --test -- `echo $i | sed -e 's!./src/!!' | sed -e 's/.php//' | sed -e 's/\//\/g'` $i `echo $i | sed -e 's!./src/!./test/!' | sed -e 's/.php/Test.php/'`;done


    Given the following directory structure:



    ./src/Superuseradmin/Model/Mapper/MyMapper.php
    ./src/Superuseradmin/Model/UUID.php


    It should output:



    phpunit-skelgen.phar --test -- SuperuseradminModelMapperMyMapper ./src/Superuseradmin/Model/Mapper/MyMapper.php ./test/Superuseradmin/Model/Mapper/MyMapperTest.php
    phpunit-skelgen.phar --test -- SuperuseradminModelUUID ./src/Superuseradmin/Model/UUID.php ./test/Superuseradmin/Model/UUIDTest.php


    You can then save this to a script, check it and run. Watch out for spaces in file names. They will cause trouble.






    share|improve this answer





















    • Why should one ever use a pipeline of several sed instances immediately after one another instead of using one sed instance with several -e parameters? Furthermore one such line is an understanding nightmare. Compute values, assign them to variables, run commands with the variables (instead of the computing expressions).
      – Hauke Laging
      May 31 '13 at 11:28










    • Ended up using a variation of this, thanks. for i in `find -type f -path "./src*" -name "*.php"`; do mkdir -p `dirname $(echo $i | sed -e 's!./src/([[:alnum:]]*)!./test/1Test!')`; phpunit-skelgen.phar --bootstrap test/Bootstrap.php --test -- `echo $i | sed -e 's!./src/!!' -e 's/.php//' -e 's!/!\\!g'` $i `echo $i | sed -e 's/.php/Test/' -e 's!./src/([[:alnum:]]*)!1Test!' -e 's!/!\\!g'` `echo $i | sed -e 's!./src/([[:alnum:]]*)!./test/1Test!' -e 's/.php/Test.php/'`;done
      – Gabriel Baker
      May 31 '13 at 17:29















    up vote
    4
    down vote



    accepted







    up vote
    4
    down vote



    accepted






    Here is a quick attempt:



    for i in `find -type f -path "./src*" -name "*.php"`; do echo phpunit-skelgen.phar --test -- `echo $i | sed -e 's!./src/!!' | sed -e 's/.php//' | sed -e 's/\//\/g'` $i `echo $i | sed -e 's!./src/!./test/!' | sed -e 's/.php/Test.php/'`;done


    Given the following directory structure:



    ./src/Superuseradmin/Model/Mapper/MyMapper.php
    ./src/Superuseradmin/Model/UUID.php


    It should output:



    phpunit-skelgen.phar --test -- SuperuseradminModelMapperMyMapper ./src/Superuseradmin/Model/Mapper/MyMapper.php ./test/Superuseradmin/Model/Mapper/MyMapperTest.php
    phpunit-skelgen.phar --test -- SuperuseradminModelUUID ./src/Superuseradmin/Model/UUID.php ./test/Superuseradmin/Model/UUIDTest.php


    You can then save this to a script, check it and run. Watch out for spaces in file names. They will cause trouble.






    share|improve this answer












    Here is a quick attempt:



    for i in `find -type f -path "./src*" -name "*.php"`; do echo phpunit-skelgen.phar --test -- `echo $i | sed -e 's!./src/!!' | sed -e 's/.php//' | sed -e 's/\//\/g'` $i `echo $i | sed -e 's!./src/!./test/!' | sed -e 's/.php/Test.php/'`;done


    Given the following directory structure:



    ./src/Superuseradmin/Model/Mapper/MyMapper.php
    ./src/Superuseradmin/Model/UUID.php


    It should output:



    phpunit-skelgen.phar --test -- SuperuseradminModelMapperMyMapper ./src/Superuseradmin/Model/Mapper/MyMapper.php ./test/Superuseradmin/Model/Mapper/MyMapperTest.php
    phpunit-skelgen.phar --test -- SuperuseradminModelUUID ./src/Superuseradmin/Model/UUID.php ./test/Superuseradmin/Model/UUIDTest.php


    You can then save this to a script, check it and run. Watch out for spaces in file names. They will cause trouble.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered May 31 '13 at 11:21









    JDaly

    561




    561












    • Why should one ever use a pipeline of several sed instances immediately after one another instead of using one sed instance with several -e parameters? Furthermore one such line is an understanding nightmare. Compute values, assign them to variables, run commands with the variables (instead of the computing expressions).
      – Hauke Laging
      May 31 '13 at 11:28










    • Ended up using a variation of this, thanks. for i in `find -type f -path "./src*" -name "*.php"`; do mkdir -p `dirname $(echo $i | sed -e 's!./src/([[:alnum:]]*)!./test/1Test!')`; phpunit-skelgen.phar --bootstrap test/Bootstrap.php --test -- `echo $i | sed -e 's!./src/!!' -e 's/.php//' -e 's!/!\\!g'` $i `echo $i | sed -e 's/.php/Test/' -e 's!./src/([[:alnum:]]*)!1Test!' -e 's!/!\\!g'` `echo $i | sed -e 's!./src/([[:alnum:]]*)!./test/1Test!' -e 's/.php/Test.php/'`;done
      – Gabriel Baker
      May 31 '13 at 17:29




















    • Why should one ever use a pipeline of several sed instances immediately after one another instead of using one sed instance with several -e parameters? Furthermore one such line is an understanding nightmare. Compute values, assign them to variables, run commands with the variables (instead of the computing expressions).
      – Hauke Laging
      May 31 '13 at 11:28










    • Ended up using a variation of this, thanks. for i in `find -type f -path "./src*" -name "*.php"`; do mkdir -p `dirname $(echo $i | sed -e 's!./src/([[:alnum:]]*)!./test/1Test!')`; phpunit-skelgen.phar --bootstrap test/Bootstrap.php --test -- `echo $i | sed -e 's!./src/!!' -e 's/.php//' -e 's!/!\\!g'` $i `echo $i | sed -e 's/.php/Test/' -e 's!./src/([[:alnum:]]*)!1Test!' -e 's!/!\\!g'` `echo $i | sed -e 's!./src/([[:alnum:]]*)!./test/1Test!' -e 's/.php/Test.php/'`;done
      – Gabriel Baker
      May 31 '13 at 17:29


















    Why should one ever use a pipeline of several sed instances immediately after one another instead of using one sed instance with several -e parameters? Furthermore one such line is an understanding nightmare. Compute values, assign them to variables, run commands with the variables (instead of the computing expressions).
    – Hauke Laging
    May 31 '13 at 11:28




    Why should one ever use a pipeline of several sed instances immediately after one another instead of using one sed instance with several -e parameters? Furthermore one such line is an understanding nightmare. Compute values, assign them to variables, run commands with the variables (instead of the computing expressions).
    – Hauke Laging
    May 31 '13 at 11:28












    Ended up using a variation of this, thanks. for i in `find -type f -path "./src*" -name "*.php"`; do mkdir -p `dirname $(echo $i | sed -e 's!./src/([[:alnum:]]*)!./test/1Test!')`; phpunit-skelgen.phar --bootstrap test/Bootstrap.php --test -- `echo $i | sed -e 's!./src/!!' -e 's/.php//' -e 's!/!\\!g'` $i `echo $i | sed -e 's/.php/Test/' -e 's!./src/([[:alnum:]]*)!1Test!' -e 's!/!\\!g'` `echo $i | sed -e 's!./src/([[:alnum:]]*)!./test/1Test!' -e 's/.php/Test.php/'`;done
    – Gabriel Baker
    May 31 '13 at 17:29






    Ended up using a variation of this, thanks. for i in `find -type f -path "./src*" -name "*.php"`; do mkdir -p `dirname $(echo $i | sed -e 's!./src/([[:alnum:]]*)!./test/1Test!')`; phpunit-skelgen.phar --bootstrap test/Bootstrap.php --test -- `echo $i | sed -e 's!./src/!!' -e 's/.php//' -e 's!/!\\!g'` $i `echo $i | sed -e 's/.php/Test/' -e 's!./src/([[:alnum:]]*)!1Test!' -e 's!/!\\!g'` `echo $i | sed -e 's!./src/([[:alnum:]]*)!./test/1Test!' -e 's/.php/Test.php/'`;done
    – Gabriel Baker
    May 31 '13 at 17:29














    up vote
    0
    down vote













    You create a shell script:



    #! /bin/bash

    find_path="./src/Superuseradmin/Model/Mapper/UUID.php"
    # find_path="$1"
    class="${find_path#./src/}" # Superuseradmin/Model/Mapper/UUID.php
    class="${class%.php}" # Superuseradmin/Model/Mapper/UUID
    class="${class////\}" # SuperuseradminModelMapperUUID
    classhead="${class%\*}" # SuperuseradminModelMapper
    classtail="${class#"$classhead"}" # UUID
    class="${classhead}${classtail}" # SuperuseradminModelMapperUUID
    # echo "class: '${class}'"

    testfile="./test${find_path#./src}"
    testfile="${testfile%.php}Test.php"
    # echo "testfile: '${testfile}'"

    echo phpunit-skelgen.phar --test -- "$class" "$find_path" "$testfile"


    And make find call this script:



    find -type f -path "./src*" -name "*.php" -exec /my/script.sh {} ;





    share|improve this answer

























      up vote
      0
      down vote













      You create a shell script:



      #! /bin/bash

      find_path="./src/Superuseradmin/Model/Mapper/UUID.php"
      # find_path="$1"
      class="${find_path#./src/}" # Superuseradmin/Model/Mapper/UUID.php
      class="${class%.php}" # Superuseradmin/Model/Mapper/UUID
      class="${class////\}" # SuperuseradminModelMapperUUID
      classhead="${class%\*}" # SuperuseradminModelMapper
      classtail="${class#"$classhead"}" # UUID
      class="${classhead}${classtail}" # SuperuseradminModelMapperUUID
      # echo "class: '${class}'"

      testfile="./test${find_path#./src}"
      testfile="${testfile%.php}Test.php"
      # echo "testfile: '${testfile}'"

      echo phpunit-skelgen.phar --test -- "$class" "$find_path" "$testfile"


      And make find call this script:



      find -type f -path "./src*" -name "*.php" -exec /my/script.sh {} ;





      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        You create a shell script:



        #! /bin/bash

        find_path="./src/Superuseradmin/Model/Mapper/UUID.php"
        # find_path="$1"
        class="${find_path#./src/}" # Superuseradmin/Model/Mapper/UUID.php
        class="${class%.php}" # Superuseradmin/Model/Mapper/UUID
        class="${class////\}" # SuperuseradminModelMapperUUID
        classhead="${class%\*}" # SuperuseradminModelMapper
        classtail="${class#"$classhead"}" # UUID
        class="${classhead}${classtail}" # SuperuseradminModelMapperUUID
        # echo "class: '${class}'"

        testfile="./test${find_path#./src}"
        testfile="${testfile%.php}Test.php"
        # echo "testfile: '${testfile}'"

        echo phpunit-skelgen.phar --test -- "$class" "$find_path" "$testfile"


        And make find call this script:



        find -type f -path "./src*" -name "*.php" -exec /my/script.sh {} ;





        share|improve this answer












        You create a shell script:



        #! /bin/bash

        find_path="./src/Superuseradmin/Model/Mapper/UUID.php"
        # find_path="$1"
        class="${find_path#./src/}" # Superuseradmin/Model/Mapper/UUID.php
        class="${class%.php}" # Superuseradmin/Model/Mapper/UUID
        class="${class////\}" # SuperuseradminModelMapperUUID
        classhead="${class%\*}" # SuperuseradminModelMapper
        classtail="${class#"$classhead"}" # UUID
        class="${classhead}${classtail}" # SuperuseradminModelMapperUUID
        # echo "class: '${class}'"

        testfile="./test${find_path#./src}"
        testfile="${testfile%.php}Test.php"
        # echo "testfile: '${testfile}'"

        echo phpunit-skelgen.phar --test -- "$class" "$find_path" "$testfile"


        And make find call this script:



        find -type f -path "./src*" -name "*.php" -exec /my/script.sh {} ;






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered May 31 '13 at 11:24









        Hauke Laging

        55.1k1283130




        55.1k1283130






















            up vote
            -1
            down vote













            Probably you want to do something like this:



            cd src
            for i in $(find . -type f -name '*.php'); do
            SRC=$i
            DST="../test/$(dirname $i)/$(basename $i php)Test.php"
            echo "copy $SRC to $DST"
            #cp $SRC $DST
            done





            share|improve this answer





















            • for i in ...; SRC=$i instead of for SRC in...? Using a mix of two variables with the same content afterwards...?
              – Hauke Laging
              May 31 '13 at 11:30










            • I'm giving an idea to illustrate what's possible.Up to you to figure out the rest
              – Marki
              May 31 '13 at 11:36










            • You give an idea what is bad coding. Up to the others to correct that. I did that (at least point it out). This bad coding has nothing to do with "what's possible" with respect to the problem to be solved.
              – Hauke Laging
              May 31 '13 at 11:38










            • Yeah, your code is the best anyway. ;-)
              – Marki
              May 31 '13 at 12:17















            up vote
            -1
            down vote













            Probably you want to do something like this:



            cd src
            for i in $(find . -type f -name '*.php'); do
            SRC=$i
            DST="../test/$(dirname $i)/$(basename $i php)Test.php"
            echo "copy $SRC to $DST"
            #cp $SRC $DST
            done





            share|improve this answer





















            • for i in ...; SRC=$i instead of for SRC in...? Using a mix of two variables with the same content afterwards...?
              – Hauke Laging
              May 31 '13 at 11:30










            • I'm giving an idea to illustrate what's possible.Up to you to figure out the rest
              – Marki
              May 31 '13 at 11:36










            • You give an idea what is bad coding. Up to the others to correct that. I did that (at least point it out). This bad coding has nothing to do with "what's possible" with respect to the problem to be solved.
              – Hauke Laging
              May 31 '13 at 11:38










            • Yeah, your code is the best anyway. ;-)
              – Marki
              May 31 '13 at 12:17













            up vote
            -1
            down vote










            up vote
            -1
            down vote









            Probably you want to do something like this:



            cd src
            for i in $(find . -type f -name '*.php'); do
            SRC=$i
            DST="../test/$(dirname $i)/$(basename $i php)Test.php"
            echo "copy $SRC to $DST"
            #cp $SRC $DST
            done





            share|improve this answer












            Probably you want to do something like this:



            cd src
            for i in $(find . -type f -name '*.php'); do
            SRC=$i
            DST="../test/$(dirname $i)/$(basename $i php)Test.php"
            echo "copy $SRC to $DST"
            #cp $SRC $DST
            done






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered May 31 '13 at 11:20









            Marki

            507210




            507210












            • for i in ...; SRC=$i instead of for SRC in...? Using a mix of two variables with the same content afterwards...?
              – Hauke Laging
              May 31 '13 at 11:30










            • I'm giving an idea to illustrate what's possible.Up to you to figure out the rest
              – Marki
              May 31 '13 at 11:36










            • You give an idea what is bad coding. Up to the others to correct that. I did that (at least point it out). This bad coding has nothing to do with "what's possible" with respect to the problem to be solved.
              – Hauke Laging
              May 31 '13 at 11:38










            • Yeah, your code is the best anyway. ;-)
              – Marki
              May 31 '13 at 12:17


















            • for i in ...; SRC=$i instead of for SRC in...? Using a mix of two variables with the same content afterwards...?
              – Hauke Laging
              May 31 '13 at 11:30










            • I'm giving an idea to illustrate what's possible.Up to you to figure out the rest
              – Marki
              May 31 '13 at 11:36










            • You give an idea what is bad coding. Up to the others to correct that. I did that (at least point it out). This bad coding has nothing to do with "what's possible" with respect to the problem to be solved.
              – Hauke Laging
              May 31 '13 at 11:38










            • Yeah, your code is the best anyway. ;-)
              – Marki
              May 31 '13 at 12:17
















            for i in ...; SRC=$i instead of for SRC in...? Using a mix of two variables with the same content afterwards...?
            – Hauke Laging
            May 31 '13 at 11:30




            for i in ...; SRC=$i instead of for SRC in...? Using a mix of two variables with the same content afterwards...?
            – Hauke Laging
            May 31 '13 at 11:30












            I'm giving an idea to illustrate what's possible.Up to you to figure out the rest
            – Marki
            May 31 '13 at 11:36




            I'm giving an idea to illustrate what's possible.Up to you to figure out the rest
            – Marki
            May 31 '13 at 11:36












            You give an idea what is bad coding. Up to the others to correct that. I did that (at least point it out). This bad coding has nothing to do with "what's possible" with respect to the problem to be solved.
            – Hauke Laging
            May 31 '13 at 11:38




            You give an idea what is bad coding. Up to the others to correct that. I did that (at least point it out). This bad coding has nothing to do with "what's possible" with respect to the problem to be solved.
            – Hauke Laging
            May 31 '13 at 11:38












            Yeah, your code is the best anyway. ;-)
            – Marki
            May 31 '13 at 12:17




            Yeah, your code is the best anyway. ;-)
            – Marki
            May 31 '13 at 12:17


















             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f77809%2fusing-shell-commands-to-manipulate-file-paths-for-use-as-arguments-to-another-pr%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Accessing regular linux commands in Huawei's Dopra Linux

            Can't connect RFCOMM socket: Host is down

            Kernel panic - not syncing: Fatal Exception in Interrupt