0

I have a command I want to run first I ran another command to get a directory which is saved in a variable:

path_white="/sys/block/sdb"

Then I want to run another command using this variable and store the output in a variable. I get errors and don't know what I am doing wrong. Any help will be appreciated.

path_pci_white=$(ll $path_white | xargs | cut -d / -f 8 | cut -b 6-13)

it seems that it is not running the entire command below is the error

/sys/block/sdb : is a directory

when i run

ll /sys/block/sdb | xargs | cut -d / -f 8 | cut -b 6-13

in the terminal i get what i want output I just want to use a variable and put the output into a variable

Thanks

8
  • Did you try path_pci_white=$(ll $(path_white) | xargs | cut -d / -f 8 | cut -b 6-13) path_withe between parenthesis ? Commented Feb 9, 2012 at 23:20
  • when i do that i get a different error such that: path_white: command not found, and ll: command not found Commented Feb 9, 2012 at 23:22
  • That's because Luc wrote $(path_white) when he meant ${path_white} (at least I hope he meant that). $(path_white) tries to run a program called path_white, as you have seen, which does not work. Commented Feb 9, 2012 at 23:27
  • @bing281: have you noticed how you have a trailing slash on the path in one case and not the other? Try changing that around and see if it matters. Commented Feb 9, 2012 at 23:28
  • yes that was just an example edit fixed. Commented Feb 9, 2012 at 23:38

2 Answers 2

2

ll is an alias for ls -l, and aliases aren't defined in shell scripts. Use an explicit ls -l instead.

Sign up to request clarification or add additional context in comments.

2 Comments

The OP didn't even state that he was running these things in a script--good psychic debugging!
Or source your rc file in your script, though I don't think this would be considered best practice.
1

There should not be a pipe after xargs. xargs takes as arguments the command it will run. Otherwise there is no point to it.

2 Comments

I don't actually follow you, however the last command above works perfectly in the terminal. ll /sys/block/sdb | xargs | cut -d / -f 8 | cut -b 6-13
Oh, then the xargs part is useless and should be removed, as all it is doing is echoing on stdout what it gets on stdin. Can you show us the output of that ll command on your system, and the desired output of the pipeline?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.