Re: [go-nuts] Using golang variable in bash script Command

2022-09-23 Thread Rich
I do a lot of 'scripting' like things with Go - I found that using 
github.com/bitfield/script makes it a TON easier to run commands and you 
can pipe a command into another command, etc. Worth checking it out. 

On Tuesday, September 20, 2022 at 9:13:03 AM UTC-4 drro...@gmail.com wrote:

> I've done this for Linux and windows, as I regularly use both.  But I used 
> a different strategy.  I used the os functions to retrieve a slice of 
> strings that I can then filter and sort as I desire.  And I use the command 
> line to get the target string.
>
> github.com/drrob1/src/dsrt
> also in that repo is ds and rex that do this. dsrtr and dsrtre search all 
> subdirectories down from the current dir for what you describe.
> And I also sort the returned list by time w/ the most recent first.
> --rob solomon
>
> On Monday, September 19, 2022 at 12:08:24 PM UTC-4 princ...@gmail.com 
> wrote:
>
>> Thank you for the response.
>>
>> On Mon, Sep 19, 2022 at 8:26 PM Tamás Gulácsi  wrote:
>>
>>> No, please, no!
>>>
>>> Do NOT use bash with string interpolation if possible!
>>> Call find directly:
>>> *cmd, err := exec.Command("find", ".", "-name", search)*
>>> princ...@gmail.com a következőt írta (2022. szeptember 19., hétfő, 
>>> 12:04:32 UTC+2):
>>>
 then we don't need to add these commands 



 *scanner := bufio.NewScanner(os.Stdin)fmt.Println("Enter the substring 
 name")scanner.Scan()search:=scanner.Text()*
  right???

 we only need to keep this one
  *cmd, err := exec.Command("bash", "-c", fmt.Sprintf("find . -name 
 %s", search))*

 On Monday, September 19, 2022 at 3:31:12 PM UTC+5:30 Jan Mercl wrote:

> On Mon, Sep 19, 2022 at 11:50 AM PK  wrote:
>
> > search:=scanner.Text()
> > cmd1,err:=exec.Command("bash", "-c", "find . -name '*$search*'")
>
> Try something like this, not tested:
>
> cmd, err := exec.Command("bash", "-c", fmt.Sprintf("find . 
> -name %s", search))
>
> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "golang-nuts" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to golang-nuts...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/golang-nuts/fb987200-6678-443f-a0ab-884b5f77c324n%40googlegroups.com
>>>  
>>> 
>>> .
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/e0e1c0b2-c976-48ca-a0fa-0be3d81397ean%40googlegroups.com.


Re: [go-nuts] Using golang variable in bash script Command

2022-09-20 Thread Robert Solomon
I've done this for Linux and windows, as I regularly use both.  But I used 
a different strategy.  I used the os functions to retrieve a slice of 
strings that I can then filter and sort as I desire.  And I use the command 
line to get the target string.

github.com/drrob1/src/dsrt
also in that repo is ds and rex that do this. dsrtr and dsrtre search all 
subdirectories down from the current dir for what you describe.
And I also sort the returned list by time w/ the most recent first.
--rob solomon

On Monday, September 19, 2022 at 12:08:24 PM UTC-4 princ...@gmail.com wrote:

> Thank you for the response.
>
> On Mon, Sep 19, 2022 at 8:26 PM Tamás Gulácsi  wrote:
>
>> No, please, no!
>>
>> Do NOT use bash with string interpolation if possible!
>> Call find directly:
>> *cmd, err := exec.Command("find", ".", "-name", search)*
>> princ...@gmail.com a következőt írta (2022. szeptember 19., hétfő, 
>> 12:04:32 UTC+2):
>>
>>> then we don't need to add these commands 
>>>
>>>
>>>
>>> *scanner := bufio.NewScanner(os.Stdin)fmt.Println("Enter the substring 
>>> name")scanner.Scan()search:=scanner.Text()*
>>>  right???
>>>
>>> we only need to keep this one
>>>  *cmd, err := exec.Command("bash", "-c", fmt.Sprintf("find . -name %s", 
>>> search))*
>>>
>>> On Monday, September 19, 2022 at 3:31:12 PM UTC+5:30 Jan Mercl wrote:
>>>
 On Mon, Sep 19, 2022 at 11:50 AM PK  wrote:

 > search:=scanner.Text()
 > cmd1,err:=exec.Command("bash", "-c", "find . -name '*$search*'")

 Try something like this, not tested:

 cmd, err := exec.Command("bash", "-c", fmt.Sprintf("find . 
 -name %s", search))

 -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/fb987200-6678-443f-a0ab-884b5f77c324n%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/f1ddd106-82e4-4e90-a585-99f62befda3bn%40googlegroups.com.


Re: [go-nuts] Using golang variable in bash script Command

2022-09-19 Thread TECHAX
Thank you for the response.

On Mon, Sep 19, 2022 at 8:26 PM Tamás Gulácsi  wrote:

> No, please, no!
>
> Do NOT use bash with string interpolation if possible!
> Call find directly:
> *cmd, err := exec.Command("find", ".", "-name", search)*
> princ...@gmail.com a következőt írta (2022. szeptember 19., hétfő,
> 12:04:32 UTC+2):
>
>> then we don't need to add these commands
>>
>>
>>
>> *scanner := bufio.NewScanner(os.Stdin)fmt.Println("Enter the substring
>> name")scanner.Scan()search:=scanner.Text()*
>>  right???
>>
>> we only need to keep this one
>>  *cmd, err := exec.Command("bash", "-c", fmt.Sprintf("find . -name %s",
>> search))*
>>
>> On Monday, September 19, 2022 at 3:31:12 PM UTC+5:30 Jan Mercl wrote:
>>
>>> On Mon, Sep 19, 2022 at 11:50 AM PK  wrote:
>>>
>>> > search:=scanner.Text()
>>> > cmd1,err:=exec.Command("bash", "-c", "find . -name '*$search*'")
>>>
>>> Try something like this, not tested:
>>>
>>> cmd, err := exec.Command("bash", "-c", fmt.Sprintf("find . -name
>>> %s", search))
>>>
>>> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/fb987200-6678-443f-a0ab-884b5f77c324n%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAEMj0xp0G6LDWAB%2BJu7%3DPUXhH3T-%3DRPAmTN%2B_zZGkWoY7sjOjA%40mail.gmail.com.


Re: [go-nuts] Using golang variable in bash script Command

2022-09-19 Thread Tamás Gulácsi
No, please, no!

Do NOT use bash with string interpolation if possible!
Call find directly:
*cmd, err := exec.Command("find", ".", "-name", search)*
princ...@gmail.com a következőt írta (2022. szeptember 19., hétfő, 12:04:32 
UTC+2):

> then we don't need to add these commands 
>
>
>
> *scanner := bufio.NewScanner(os.Stdin)fmt.Println("Enter the substring 
> name")scanner.Scan()search:=scanner.Text()*
>  right???
>
> we only need to keep this one
>  *cmd, err := exec.Command("bash", "-c", fmt.Sprintf("find . -name %s", 
> search))*
>
> On Monday, September 19, 2022 at 3:31:12 PM UTC+5:30 Jan Mercl wrote:
>
>> On Mon, Sep 19, 2022 at 11:50 AM PK  wrote:
>>
>> > search:=scanner.Text()
>> > cmd1,err:=exec.Command("bash", "-c", "find . -name '*$search*'")
>>
>> Try something like this, not tested:
>>
>> cmd, err := exec.Command("bash", "-c", fmt.Sprintf("find . -name 
>> %s", search))
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/fb987200-6678-443f-a0ab-884b5f77c324n%40googlegroups.com.


Re: [go-nuts] Using golang variable in bash script Command

2022-09-19 Thread PK
then we don't need to add these commands 



*scanner := bufio.NewScanner(os.Stdin)fmt.Println("Enter the substring 
name")scanner.Scan()search:=scanner.Text()*
 right???

we only need to keep this one
 *cmd, err := exec.Command("bash", "-c", fmt.Sprintf("find . -name %s", 
search))*

On Monday, September 19, 2022 at 3:31:12 PM UTC+5:30 Jan Mercl wrote:

> On Mon, Sep 19, 2022 at 11:50 AM PK  wrote:
>
> > search:=scanner.Text()
> > cmd1,err:=exec.Command("bash", "-c", "find . -name '*$search*'")
>
> Try something like this, not tested:
>
> cmd, err := exec.Command("bash", "-c", fmt.Sprintf("find . -name 
> %s", search))
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/af021af3-6521-470a-a813-d6977e9bf823n%40googlegroups.com.


Re: [go-nuts] Using golang variable in bash script Command

2022-09-19 Thread Jan Mercl
On Mon, Sep 19, 2022 at 11:50 AM PK  wrote:

> search:=scanner.Text()
> cmd1,err:=exec.Command("bash", "-c", "find . -name '*$search*'")

Try something like this, not tested:

cmd, err := exec.Command("bash", "-c", fmt.Sprintf("find . -name
%s", search))

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAA40n-Up7L%2B%3D%3DcRSftkwvn7VBWDLmpsJmeY%2B8TVTkfzjnd-JMQ%40mail.gmail.com.


[go-nuts] Using golang variable in bash script Command

2022-09-19 Thread PK
HI everyone, can anyone help me with this:
I want to list all the files having some user's entered string as substring 
in their name.
So I wrote these commands:





*scanner := bufio.NewScanner(os.Stdin)fmt.Println("Enter the substring 
name")scanner.Scan()search:=scanner.Text()cmd1,err:=exec.Command("bash", 
"-c", "find . -name '*$search*'")*

But I think the variable search is not getting used inside exec command.

Can anyone please let me know, how I can use the golang variable in bash 
command this?

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/3f74da22-624c-4aa9-abc6-9d61943c1c82n%40googlegroups.com.