using adb push to transfer files to an android device

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
Oren Medicks

using adb push to transfer files to an android device

Post by Oren Medicks »

Hi there!
I ma trying to use this alias to routinely copy a file to my android device (rooted Galaxy 7), my OS is Mint 20.1 Cinnamon.

alias acim=adb push /home/oren/Downloads/???.mp3 storage/0012-4040/audiobooks/'ACIM lessons'
the wildcards mean the file name will always be numbers between 100 - 400

ADB only returns its help screen, with no error.

Running the same command through terminal, without the alias works just fine.

An idea why it wouldn't work as alias?

Any help will be much appreciated

Oren
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
1000
Level 6
Level 6
Posts: 1039
Joined: Wed Jul 29, 2020 2:14 am

Re: using adb push to transfer files to an android device

Post by 1000 »

You can not create alias if command not working from terminal.
Is the path correct? 'hero2lte:/storage/0012-4040/audiobooks/ACIM lessons'
Welcome
Level 6
Level 6
Posts: 1026
Joined: Wed Aug 19, 2020 11:38 am

Re: using adb push to transfer files to an android device

Post by Welcome »

Edit: To revisit the context, OP's original post had ...

Code: Select all

alias acim='adb push /home/oren/Downloads/???.mp3 hero2lte:storage/0012-4040/audiobooks/ACIM lessons'
Android directory "ACIM lessons" with a space ...
Last edited by Welcome on Thu Mar 04, 2021 12:11 pm, edited 2 times in total.
Oren Medicks

Re: using adb push to transfer files to an android device

Post by Oren Medicks »

Thank you all for chiming in!
As 1000 suggested, the path was incorrect ( I edited my original post to reflect the correction)

Now the command works well from the terminal -

oren@oren-V530S-07ICB:~$ adb push /home/oren/Downloads/???.mp3 storage/0012-4040/audiobooks/'ACIM lessons'
/home/oren/Downloads/222.mp3: 1 file p...ed. 10.4 MB/s (514033 bytes in 0.047s)

but still, as alias, I still just get the adb help screen.
1000
Level 6
Level 6
Posts: 1039
Joined: Wed Jul 29, 2020 2:14 am

Re: using adb push to transfer files to an android device

Post by 1000 »

Try something like this add

Code: Select all

###########################{
MY_ACIM(){
adb push /home/oren/Downloads/???.mp3 storage/0012-4040/audiobooks/'ACIM lessons'
}

# USAGE: acim
alias acim='MY_ACIM'
###########################}
Reload the base

Code: Select all

source ~/.bashrc
( However I don't know where you want save alias. I guess that you added alias in ~/.bashrc file )
and test acim command.
Last edited by 1000 on Tue Mar 02, 2021 2:46 pm, edited 2 times in total.
Oren Medicks

Re: using adb push to transfer files to an android device

Post by Oren Medicks »

This works perfectly!
Thanks a lot!
User avatar
Termy
Level 12
Level 12
Posts: 4248
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: using adb push to transfer files to an android device

Post by Termy »

It's not properly quoted. This should work:

Code: Select all

alias acim='adb push /home/oren/Downloads/???.mp3 storage/0012-4040/audiobooks/ACIM\ lessons'
I'm also Terminalforlife on GitHub.
Moonstone Man
Level 16
Level 16
Posts: 6054
Joined: Mon Aug 27, 2012 10:17 pm

Re: using adb push to transfer files to an android device

Post by Moonstone Man »

Termy wrote: Wed Mar 03, 2021 9:02 pm It's not properly quoted.
You beat me to it.
User avatar
Termy
Level 12
Level 12
Posts: 4248
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: using adb push to transfer files to an android device

Post by Termy »

Thinking about it, rather than telling you it's wrong, it'd be better to explain why. So let's look at what you typed:

Code: Select all

alias acim=adb push /home/oren/Downloads/???.mp3 storage/0012-4040/audiobooks/'ACIM lessons'
The shell, not too surprisingly, typically reads from left-to-right (exceptions are well outside the scope of this thread). The shell, therefore, will first see alias, which is a BASH builtin, meaning it's built into the shell. I'm assuming you're using BASH, by the way. You probably have an idea what alias does, because you're using it right there. :P

After alias, the shell will see the acim=adb word (shell's idea of a word) which alias interprets to mean that acim is to be the name associated with the alias, and it equals the value of adb. However, then it sees the rest: a series of out-of-place words which appear as though they were additional arguments to the alias builtin. As expected, the builtin errors out.

The reason what I posted should work, is because it keeps the entire command you want assigned to the acim alias together, as part of the one argument, which is in the syntax of alias NAME=COMMAND.

You might've noticed I changed your 'ACIM lessons' to ACIM\ lessons; that's because the shell would get confused seeing multiple pairs of apostrophes (AKA: single-quotes). It works because I've escaped the space, effectively stopping the shell (when you actually use the alias) from interpreting ACIM (and stuff before it) and lessons as two separate fields.

Hope that helped, or at the very least was interesting to you and/or passers-by. :)
Last edited by Termy on Thu Mar 04, 2021 11:03 am, edited 1 time in total.
I'm also Terminalforlife on GitHub.
Oren Medicks

Re: using adb push to transfer files to an android device

Post by Oren Medicks »

Thank you very much for this elaborate and insightful reply.
It not only helped by solving the problem; It will surely be very useful in future attempts to write commands, aliases etc.
All the very best!
User avatar
Termy
Level 12
Level 12
Posts: 4248
Joined: Mon Sep 04, 2017 8:49 pm
Location: UK
Contact:

Re: using adb push to transfer files to an android device

Post by Termy »

:D That puts a nice big smile on my face. Happy to help!
I'm also Terminalforlife on GitHub.
Locked

Return to “Scripts & Bash”