« first day (1807 days earlier)      last day (1232 days later) » 

4:45 AM
@Queen k
@Queen k Community
 
 
8 hours later…
12:33 PM
@tripleee : is it possible to push several directories into DIRSTACK with a single operation ?
 
@louigi600 weird question, why would you? No, I can't seem to find a way to do that, but I haven't tried very hard
 
I'm writing some code to show the use of DIRSTACK
I use set -x
and set+x
to echo the comands in junction with subshel piped with sed to make it seem like it's all hapening for real
Example
echo "Now let's try adding some stuff into the DIRSTACK:
    "

    ( set -x
      pushd -n /doesnotexist
      pushd -n /doesnotexist2
      pushd -n /doesnotexist3
      set +x ) 2>&1 | sed 's/^+ set +x//; s/^+/#/'
being a subshell I loose the DIRSTACK content each time
Want to set it up with a single command if possible
if I can do it with a single command then I can suppress it easy in the output
 
use braces instead of parentheses to run it in the current shell
 
ok let me try
 
$ { set -x; pushd -n one; pushd -n two; pushd -n three; set +x; }
+ pushd -n one
~/charcoal/SmokeDetector/.git one
+ pushd -n two
~/charcoal/SmokeDetector/.git two one
+ pushd -n three
~/charcoal/SmokeDetector/.git three two one
+ set +x
$ dirs
~/charcoal/SmokeDetector/.git three two one
 
12:42 PM
something went bad ... maybe with the piping with sed
 
ah yes, that would be a problem in fact
 
it would work if I need not pipe with something the stuff in the praces
maybe I can have a function do the mushd
and call the mushd before the the set -x
I do hereditate the function def in the subshell right ?
mpushd ()
{ while [ $# -ge 1 ]
  do
    pushd -n $1
    shift
  done
}
 
1:00 PM
inherit? you have to export -f mpushd
 
it seems to be working washout that
exort -f is for exporting files ...
I'm defining it inside the script so I don't need that
 
export -f funcname makes funcname visible to subshells
 
ooops I read wrong the man page
but then why is it working ?
I did not export the function
 
if the same script uses the function you don't need to export it ... I guess Bash handles this for you if it can see lexically that the function is called from within parentheses
bash-3.2$ type -all poo
bash: type: poo: not found
bash-3.2$ poo () { echo poo; }
bash-3.2$ ( poo )
poo
bash-3.2$ bash -c 'poo'
bash: poo: command not found
 
ok I get it I think
I cant get this to work with double quotes
sed 's/^+ set +x//; s/^+/#/'
need it because I want to use a variable in another substitution
 
1:16 PM
I'm guessing you want /^+ set +x/d btw
there is nothing there which works differently within double quotes; they only make a difference if you have a double quote, backslash, dollar sign, or backtick
if you have a variable there, I'm guessing the problem is in its value
 
I want to make the beginning + in the output of sed -x into #
and suppress the sed +x altogether
( set -x
dirs
set +x
) 2>&1 | sed 's/^+ set +x//; s/^+/#/'
 
works for me
$ ( set -x; dirs; set +x ) 2>&1 | sed "/^+ set +x/d;s/^+/#/"
# dirs
~/charcoal/SmokeDetector ~/charcoal/SmokeDetector
 
want to add a new substitution do get rid of this sort of thing:
./dirstack.sh: line 50: pushd: /nodirectory: No such file or directory
in particular just remove
./dirstack.sh: line 50:
where "./dirstack.sh" is actually $0
 
$ ( set -x; dirs; carp; set +x ) 2>&1 | sed "/^+ set +x/d;s/^+/#/"
# dirs
~/charcoal/SmokeDetector ~/charcoal/SmokeDetector
# carp
-bash: carp: command not found

$ ( set -x; dirs; carp; set +x ) 2>&1 | sed "/^+ set +x/d;s/^+/#/;s/^$0: //"
# dirs
~/charcoal/SmokeDetector ~/charcoal/SmokeDetector
# carp
carp: command not found
ohhh you are trying to use s/// around a value with a slash ... just use a different delimiter, like s%%%
this is a <big><blink><bold>very</bold></blink></big> common FAQ
 
I did something wrong .... let me sort it out ....
dont thnk so .... damn it this crappy keyboard that randomly misses keys
let me show you the problem
( mpushd /doesnotexist3 /doesnotexist2 /doesnotexist
  set -x
  pushd /nodirectory
  dirs
  set +x
) 2>&1 | sed "/^+ set +x/d; s/^+/#/"
that producesthis:
./dirstack.sh: line 45: mpushd: command not found
# pushd /nodirectory
./dirstack.sh: line 47: pushd: /nodirectory: No such file or directory
# dirs
~
 
1:32 PM
yes ...? And now you tried "s/^$0://" and it doesn't work because you have a slash in $0
 
now I don't want it to be evident it's a script (dirstack.sh) so I want to remove
"./dirstack.sh: line 47: pushd: "
at the begining of the line
./dirstack.sh: line 47: pushd: /nodirectory: No such file or directory
just leave
pushd: /nodirectory: No such file or directory
 
if you want to remove the prefix, "s%^$0: %%"; if you want to delete the whole line, "\\%^$0: %d" -- tricky because you need to double the backslash in double quotes
 
I don't want the substitution to have exlicitly ./dirstack.sh
I want to use $0
 
oh well "s%^$0: line [1-9][0-9]*: %%" if you want to pluck off the line number too
 
why di I need to use % instead of / ?
 
1:40 PM
because sed thinks every slash is a separator if you use slash as separator
think about it; you just pass in a string; by the time it reaches sed, it has no idea which of those slashes came from inside a variable and which ones were part of your original command
equivalently you could backslash-escape every character which has a meaning to sed (and any regex metacharacter you want to match literally)
 
ok so iy is because of the expansion of $0
I get it now
 
if you have x="///" and sed "s/$x/$x$x/" by the time the shell has expanded the variable, sed only sees s////////////
 
 
2 hours later…

« first day (1807 days earlier)      last day (1232 days later) »