Command option substitution?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Command option substitution?
# 1  
Old 12-09-2017
Command option substitution?

Hi folks,

I totally dislike asking questions in forums but this one eats up to much of my time I need to spend on other topics.

I have a shell-script in which I call a terminal.
I want to invoke bash inside the terminal and print a message inside bash with aid of a here document.

See yourself.

Code:
( DISPLAY=:0 xfce4-terminal --command /bin/bash & )

works just fine and opens up a terminal with bash inside. But if I try to pass a command to bash itself the script fails.

Code:
( DISPLAY=:0 xfce4-terminal --command /bin/bash <(cat <<EOF some stupid text EOF) & )

I don't get it working.
A much nicer approach would be if I can pass a function (declared and defined) to bash?

I suppose the problem is, that bash is running in the context of the subshell of the terminal but my imagination and knowledge ends there.

I am almost sure that piping the result of a function in such a nested scenario is impossible.

Greets

bluntroller
# 2  
Old 12-09-2017
Here documents require that EOF is at the start of the on a separate line and that is the only text on the line, so using you code as an example, you would need something like this
Code:
    cat <<EOF
echo some stupid text 
EOF

Alternatively you could use a here-string

Passing a function is possible with bash through an export of the function, but can this easily become a security risk, so imho is best avoided.

For passing text to a sub process you can use a named pipe if you just want it to display the message,
or use bash 4's coproc functionality for a two-way pipe.

Last edited by Scrutinizer; 12-09-2017 at 07:09 AM..
# 3  
Old 12-09-2017
Hey,

thanks for the 'input'.
Appreciate.
Of course, you are right about 'the thing' with EOF. My fault.

Anyway.... the terminal still pops up without the message I'd like to display.

The command in the argument of the invocation of bash simply doesn't get validated no matter which approach I take.
# 4  
Old 12-09-2017
Try something like this:
Code:
( DISPLAY=:0 xfce4-terminal --command /bin/bash -c "echo hello; sleep 10" & )


Last edited by Scrutinizer; 12-10-2017 at 04:24 PM..
# 5  
Old 12-09-2017
Quote:
Originally Posted by Scrutinizer
Try something like this:
Code:
DISPLAY=:0 xfce4-terminal --command /bin/bash -c "echo hello; sleep 10" &

nope

:-)

---------- Post updated at 06:43 AM ---------- Previous update was at 06:25 AM ----------

I'd really like to avoid it but I guess I am simply going to put the message in a file. I hate it if things don't work out like I want it. .-)

If someone knows a one-line solution I'd really like to know it!
But it seems difficult as there are several subshells involved and bash supposedly has some security mechanisms in conflict with the task to solve.

Thanks for your considerations.

Am out
# 6  
Old 12-09-2017
I'm sorry things aren't working out the way you want. But I'm confused as to what exactly is going wrong. You say that:
Code:
( DISPLAY=:0 xfce4-terminal --command /bin/bash & )

works. You said that some unspecified command fails, but don't show us what command you used and you don't tell us how it failed. Without clearly seeing what you're trying to do and knowing how what you have tried fails, it is really hard to suggest alternatives that might work for you.

Please show us what command you are trying to get bash to run in the terminal window you are opening, tell us what output is being produced, and tell us what output you were hoping to produce.
# 7  
Old 12-09-2017
Take any binary in /bin.

I thought it was self-explaining and didn't need any further explanation what I am trying to accomplish with this quite easy to understand fragment of a script.

Well, I just tried to present a solution but the ******* code-tags don't like my strict browser settings I guess.

However, the man page of the terminals might help... helps..


However, I am a bit ****** off actually because of the whole java-stuff going on this server stealing my time. I asked for the delete of my account.

I am afraid I am no more interested in the post.
Sorry.

Greets

George

Last edited by Scott; 12-09-2017 at 05:42 PM.. Reason: Removed profanity
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Regarding command substitution

Oracle Linux 5.6, 64-bit Given the following snippet wrkvar=`sqlplus -s / as sysdba <<EOF set echo off feedback off head off trimsp on select count(*) from v\$parameter where name in ('db_file_name_convert','log_file_name_convert') and value is not null; EOF` echo wrkvar=$wrkvarProduces... (2 Replies)
Discussion started by: edstevens
2 Replies

2. Shell Programming and Scripting

Substitution within string command

I have the following code: strfuture=abcdefghi ver=${strfuture:${count}:1} mj7777_ver=${ver} start_mj7777_iteration let count=count+1 When it is executed I get bad substitution. The same if I use ver=${strfuture:$count:1} mj7777_ver=${ver}... (6 Replies)
Discussion started by: Bruble
6 Replies

3. Shell Programming and Scripting

command substitution doubt

Hi, I almost always use back quotes in scripts to assigin output of a command to a variable. eg: file=`basename a/b/c/d/file` year_mon=`date +%Y%m` But the same can be achieved like: file=$(basename a/b/c/d/file) year_mon=$(date +%Y%m) I would like to know if there is... (3 Replies)
Discussion started by: wanderingmind16
3 Replies

4. UNIX for Advanced & Expert Users

Help with command substitution in C program

Hi, I want to know if there's a cleaner way for assigning output of a unix command to a variable in C program . Example : I execute dirname fname and want the output to be assigned to a variable dname . Is it possible . I knew u can redirect the output to a file and then reread assigning... (5 Replies)
Discussion started by: royalbull
5 Replies

5. Shell Programming and Scripting

Repeating Substitution Command on VI

Hello Folks, how to write a command on vi that allow to repeat last substitution command? Here what I want to do : 1 2 3 1 2 3 1 2 3 :.,+2s/\n/ /And I obtain : 1 2 3 1 2 3 1 (5 Replies)
Discussion started by: gogol_bordello
5 Replies

6. UNIX for Dummies Questions & Answers

read command - using output from command substitution

Hey, guys! Trying to research this is such a pain since the read command itself is a common word. Try searching "unix OR linux read command examples" or using the command substitution keyword. :eek: So, I wanted to use a command statement similar to the following. This is kinda taken... (2 Replies)
Discussion started by: ProGrammar
2 Replies

7. UNIX for Dummies Questions & Answers

sed insert command and variable expansion/command substitution

I know this script is crummy, but I was just messing around.. how do I get sed's insert command to allow variable expansion to show the filename? #!/bin/bash filename=`echo $0` /usr/bin/sed '/#include/ { i\ the filename is `$filename` }' $1 exit 0 (8 Replies)
Discussion started by: glev2005
8 Replies

8. UNIX for Dummies Questions & Answers

Command substitution within an echo

I'm trying to get this to work and I'm not really sure how to do it. echo $x | awk '{print $NF}' MODIFIEDThe output I'm trying to get should look like: dir1 MODIFIED Where dir1 will be the result of: $x |awk '{print $NF}'I'm sure there's something I'm supposed to put around that part... (3 Replies)
Discussion started by: ewoods
3 Replies

9. Shell Programming and Scripting

Difference between "Command substitution" and "Process substitution"

Hi, What is the actual difference between these two? Why the following code works for process substitution and fails for command substitution? while IFS= read -r line; do echo $line; done < <(cat file)executes successfully and display the contents of the file But, while IFS='\n' read -r... (3 Replies)
Discussion started by: royalibrahim
3 Replies

10. Shell Programming and Scripting

Substitution of last command

"Is there any substituation of last command or script syntax which can be used as a user. As far I know the "last" command is being used to display information about previous logins. A member of adm group or the user adm can execute it only. Thanks in advance for your usual help. Ghazi (6 Replies)
Discussion started by: ghazi
6 Replies
Login or Register to Ask a Question