Bash - command substution not working


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Old 11-23-2014
Bash - command substution not working

For some reason I cannot use command substitution in my bash shell in Fedora.

Code:
 
 The following commands give me the following outputs-:
  
 [Sreyan@localhost ~]$ $(( $(w| wc -l) - 2 ))
Command not found. 
 
[Sreyan@localhost ~]$ `ls`
Command not found. 
 
[Sreyan@localhost ~]$ $("date")
Command not found. 
 [Sreyan@localhost ~]$ $(ls)
Command not found. 
 [Sreyan@localhost ~]$ $(( $(date +%s) / 86400 ))
Command not found.

What am I doing wrong ? I cannot complete my assignments without command substitution. That's why I am posting here. I am on Fedora 14 32bit.
# 3  
Old 11-23-2014
Quote:
Originally Posted by derekludwig
What is your PATH environmental variable set to?
(hint: echo $PATH)
Code:
/usr/lib/qt-3.3/bin:/usr/lib/ccache:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/Sreyan/bin

# 4  
Old 11-23-2014
You do not need to put date, ls, or any other COMMAND to put in quotes when executed in a terminal.

Just like this is enough:
Code:
date
ls
w

To actualy work with them, it is suggest to echo them when encapsuled in a XY (what is this called again?).
As in:
Code:
echo $(( $(w| wc -l) - 2 ))
echo $(( $(date +%s) / 86400 ))

Because if you just call:
Code:
$(( $(date +%s) / 86400 ))

It will fail, because its result is not a COMMAND.

Furthermore (but not relevant to the post), F14 is way end of life, 21 is coming out soon.

Hope this helps
These 2 Users Gave Thanks to sea For This Post:
derekludwig (11-23-2014) sreyan32 (11-23-2014)
# 5  
Old 11-23-2014
Quote:
Originally Posted by sea
You do not need to put date, ls, or any other COMMAND to put in quotes when executed in a terminal.

Just like this is enough:
Code:
date
ls
w

To actualy work with them, it is suggest to echo them when encapsuled in a XY (what is this called again?).
As in:
Code:
echo $(( $(w| wc -l) - 2 ))
echo $(( $(date +%s) / 86400 ))

Because if you just call:
Code:
$(( $(date +%s) / 86400 ))

It will fail, because its result is not a COMMAND.

Furthermore (but not relevant to the post), F14 is way end of life, 21 is coming out soon.

Hope this helps
Thanks that solved my problem. Don't know what you mean by F14 though.
# 6  
Old 11-23-2014
Quote:
Originally Posted by sreyan32
...
That's why I am posting here. I am on Fedora 14 32bit.
F14 = Fedora 14
Just saying that version 20 is out: Fedora Project - Get Fedora: Desktops, Other Formats, Spins, Cloud Images, ARM or Secondary Arches.

Cheers
# 7  
Old 11-25-2014
I'd recommend updating tot he latest version. 14 is a very long way behind.
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Best way to get a bash script working in C Knogle Programming 2 11-08-2018 11:15 AM
How to run several bash commands put in bash command line? abdulbadii Shell Programming and Scripting 4 01-23-2018 06:11 AM
Bash counter increment not working Zel2008 Shell Programming and Scripting 6 05-30-2014 10:11 AM
Working with grep and Bash Njzangel Shell Programming and Scripting 6 02-20-2013 03:22 AM
sed not working in a bash script jacobs.smith Shell Programming and Scripting 1 01-18-2013 11:20 AM
Bash join script not working Nostyx Shell Programming and Scripting 2 11-29-2011 03:56 PM
Working with bash and date Lord Spectre Shell Programming and Scripting 8 01-20-2011 11:08 AM
Need help! command working ok when executed in command line, but fails when run inside a script! 4dirk1 Shell Programming and Scripting 4 12-02-2010 05:47 AM
Why Bash is not working in HP-UX ? girija HP-UX 9 08-07-2010 07:01 PM
BASH: Factorial using FOR loop not working Technext Shell Programming and Scripting 3 07-17-2010 07:58 AM
export not working in Bash shell amit.behera Shell Programming and Scripting 6 03-11-2010 04:35 AM
Simple BASH script not working? doubleminus Shell Programming and Scripting 4 05-13-2009 06:13 PM
if loop not working in BASH shell npatwardhan Shell Programming and Scripting 10 11-10-2008 09:35 AM
Solaris 8 installed but bash is not working bluridge Solaris 2 01-24-2008 04:03 PM
#!/bin/bash has stopped working zorrokan Shell Programming and Scripting 2 09-21-2007 03:02 AM